longest sequence

Brian Quinlan brian at sweetapp.com
Mon Feb 17 19:00:47 CET 2003


> Yay, optimizations time! :-)
> 
> def longest2(*args):
>    if args:
>       decorated = [ (len(S),S) for S in args ]
>       decorated.sort()
>       return decorated[-1][1]

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?

Cheers,
Brian






More information about the Python-list mailing list