max() of a list of tuples

Erik Max Francis max at
Wed Jan 22 06:48:16 CET 2003

David Eppstein wrote:

> 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.

The final argument would only be necessary in the edge case where the
list of tuples is empty:

>>> reduce(max, [3, 4, 5, 2])
>>> reduce(max, [3])
>>> reduce(max, [])
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: reduce() of empty sequence with no initial value

Certainly that can be handled as a special case and reduce would simply
not be needed to be called in the first place.

 Erik Max Francis / max at /
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ I love Mickey Mouse more than any woman I've ever known.
\__/ Walt Disney /
 The best hard science Web sites that the Web has to offer.

More information about the Python-list mailing list