max() of a list of tuples
David Eppstein
eppstein at ics.uci.edu
Wed Jan 22 00:22:10 EST 2003
In article <b0l57d$12j$1 at wheel2.two14.net>,
Martin Maney <maney at pobox.com> wrote:
> 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?
What I wonder is, why supply the final argument to reduce at all?
Without the argument, it will work with non-numeric tuple values.
With the argument, the values have to be comparable to floats.
--
David Eppstein UC Irvine Dept. of Information & Computer Science
eppstein at ics.uci.edu http://www.ics.uci.edu/~eppstein/
More information about the Python-list
mailing list