String splitting question

William Park opengeometry at yahoo.ca
Wed Apr 9 03:33:32 EDT 2003


Jim Shady <iamshady at rediffmail.com> 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. For
> example, longest_str() for the above line should return
> 'abcdefghijkl'. How do I go about doing this?

out = []
for i in 'abcd/df/a/iiwk/abcdefghijkl/b/c'.split('/'):
    out.append( (len(i), i) )
print max(out)[1]

-- 
William Park, Open Geometry Consulting, <opengeometry at yahoo.ca>
Linux solution for data management and processing. 




More information about the Python-list mailing list