String splitting question

Paul Rubin http
Wed Apr 9 12:13:07 EDT 2003


iamshady at rediffmail.com (Jim Shady) writes:
> 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?

def longest_str(s):
  lengths = [len(x) for x in s.split('/')]
  return max(lengths)




More information about the Python-list mailing list