[Python-ideas] max() allowed to take empty list

Mark Dickinson dickinsm at gmail.com
Tue Apr 13 11:05:52 CEST 2010


On Tue, Apr 13, 2010 at 2:52 AM, Chris Rebert <pyideas at rebertia.com> wrote:
> Adding a 'default value' parameter to max() to be returned when the
> iterable is empty would make slightly more sense.

This has been proposed (and rejected) before:

http://bugs.python.org/issue7153

Previous python-ideas thread:

http://mail.python.org/pipermail/python-ideas/2009-April/004107.html

The main problems (opportunities!) were:

(1) the API for max and min is already complicated (single iterable
argument versus multiple scalar arguments; 'key' parameter), and it's
difficult to see how to clearly extend the API to take a default value

(2) it wasn't clear whether it would make more sense to have a
'default' value---i.e., something that would be returned if the
iterable is empty, and completely ignored otherwise, or a 'start'
value---something that's added in to the mix of values in the
iterable, so that the result is effectively the max of <iterable> +
<[start]>.

Mark



More information about the Python-ideas mailing list