String splitting question

Thomas Guettler pan-newsreader at thomas-guettler.de
Wed Apr 9 08:58:37 CEST 2003


On Wed, 09 Apr 2003 08:45:42 +0200, Jim Shady wrote:

> Hello,
> 
> I am a beginner at Python and I just joined this group.
> 
> I have a string:
> 
> abcd/df/a/iiwk/abcdefghijkl/b/c
> 
> I need to get the longest string between the /s of the string. 

Hi,

this is one solution

s="x/aa/"
s=s.split("/")
max_item=None
max_len=-1
for item in s:
    if len(item)>max_len:
        max_item=item
        max_len=len(item)
print "Max:", max_item, max_len

 thomas

-- 
Thomas Guettler <guettli at thomas-guettler.de>
http://www.thomas-guettler.de




More information about the Python-list mailing list