how to find the longst element list of lists

Jussi Salmela tiedon_jano at hotmail.com
Sun Jan 7 22:42:06 CET 2007


Michael M. kirjoitti:
> How to find the longst element list of lists?
> 
> I think, there should be an easier way then this:
> 
>   s1 = ["q", "e", "d"]
>   s2 = ["a", "b"]
>   s3 = ["a", "b", "c", "d"]
> 
> <snip>
> 
> After, the list ist sorted:
> 
>   sx1 = ["a", "b", "c", "d"]
>   sx2 = ["q", "e", "d"]
>   sx3 = ["a", "b"]
> 

s1 = ["q", "e", "d"]
s2 = ["a", "b"]
s3 = ["a", "b", "c", "d"]
ss = ((len(s1), s1), (len(s2), s2), (len(s3), s3))
sx = [y for (x, y) in sorted(ss)[::-1]]
print sx
sx1, sx2, sx3 = sx
print sx1, sx2, sx3


Cheers,
Jussi



More information about the Python-list mailing list