[issue18111] Add a default argument to min & max

Raymond Hettinger report at bugs.python.org
Tue Jun 4 05:34:19 CEST 2013


Raymond Hettinger added the comment:

Guido, this is your language.  What would you like to do?

The OP wants a default argument on min() and max() so he won't have to use an "except ValueError" for non-sequence iterables that are potentially empty.

At first, I thought the functions were already as complex as we would want to get, but several proponents have emerged, so I'm stepping aside.

The proposed patch would allow:
   max(iterable, key=somefunc, default=sentinel)
and would return sentinel_value when len(list(iterable))==0.

It would not allow:
   max(*iterable, key=somefunc, default=sentinel_value)
where s is an empty iterable.

----------
assignee:  -> gvanrossum
nosy: +gvanrossum

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue18111>
_______________________________________


More information about the Python-bugs-list mailing list