max() of a list of tuples

Mario Wehbrink wehbrink at web.de
Tue Jan 21 11:41:03 CET 2003


Am Die, 21 Jan 2003 schrieb Max M in comp.lang.python:

> Mario Wehbrink wrote:
> 
> > [maximum of list of tuples]
> 
> 
> l = [(1,3,5), (8,16,2), (2,56,4)]
> print max([(i[-1],i) for i in l])[1]
> 
>  >>> (1,3,5)

Nice and elegant! Thanks. Although i don't understand how it works :-/

Mario




More information about the Python-list mailing list