max() of a list of tuples

Martin Maney maney at pobox.com
Tue Jan 21 23:03:57 EST 2003


Peter Abel <p-abel at t-online.de> wrote:
> Silly me!!!
> The correct code is:
>>>> l = [(1, 3, 5), (8, 16, 2), (2, 56, 4)]
>>>> reduce(lambda y,x:y[2]>x[2] and y or x,l,(-1.e16,-1.e16,-1.e16))
> (1, 3, 5)

Why not (None,None,None) as the initial value?

(no, really, I don't know.  it just seemed natural in the same way that
thinking "reduce is the answer" seemed as it popped into my head when I
first saw the OP's question.  None does seem to compare as less than
anything else (and, yeah, trying it seemed more natural than looking it
up - I think Python may be eating my mind, but I can't bring myself to
worry about it))




More information about the Python-list mailing list