max() of a list of tuples
Erik Max Francis
max at alcyone.com
Fri Jan 24 01:54:26 CET 2003
Peter Abel wrote:
> And if there's no initial value, it seems the
> reduce-function starts with the first element of l.
> (As I said l <wink>)
Well, of course. That's what reduce _does_. It repeatedly applies a
binary function to the elements of the sequence, accumulating the
result. Specifying the third argument -- the initial value -- is only
necessary if 1. the sequence is empty or 2. you want the initial value
to be something other than what it would normally be.
The vagueness here is, of course, because reduce works on _any_ function
that accumulates values over any types of elements, not just numeric
reduce(f, S, i)
is really precisely equivalent to
reduce(f, [i] + S),
provided of course that the sequence is compatible with being added to a
Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
__ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/ \ An undevout astronomer is mad.
\__/ Edward Young
Bosskey.net: Quake III Arena / http://www.bosskey.net/q3a/
A personal guide to Quake III Arena.
More information about the Python-list