longest sequence

Evan Simpson evan at 4-am.com
Mon Feb 17 13:12:01 EST 2003


Brian Quinlan wrote:
> You didn't fix the important part: this is still a O(nlogn) solution to
> an O(n) problem. Of course *args is likely to be small so who cares?

True enough.  Who can resist the opportunity for a one-liner that uses a 
list comprehesion, though?

def longest(*args):
     return max([(len(s), s) for s in args])[1]

Cheers,

Evan @ 4-am







More information about the Python-list mailing list