[Tutor] Length of longest item in a list, using a list comp

Kent Johnson kent37 at tds.net
Thu Dec 28 23:21:03 CET 2006


Andreas Kostyrka wrote:
> With 2.5 you can even do stuff like that:
> 
>>>> x=[range(5), range(3), range(7)]
>>>> max(x, key=lambda i: len(i))
> [0, 1, 2, 3, 4, 5, 6]

No need for the lambda, just use
max(x, key=len)

Kent



More information about the Tutor mailing list