String splitting question
Nicola Paolucci
durdn at yahoo.it.oops!.invalid
Wed Apr 9 14:08:02 EDT 2003
Hello Jim,
Jim Shady wrote:
> 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?
I didn't read all the other replies since I wanted to come up with a
solution myself (so all excuse me if somebody suggested a similar thing):
>>> p = 'abcd/df/a/iiwk/abcdefghijkl/b/c'
>>> max([(len(e),e) for e in p.split('/')])[1]
'abcdefghijkl'
This did it for me.
Best regards,
Nicola Paolucci
--
#Remove .oops!.invalid to email or feed to Python:
'Tmljb2xhIFBhb2x1Y2NpIDxuaWNrQG5vdGp1c3RjYy5jb20+'.decode('base64')
More information about the Python-list
mailing list