[Python-ideas] Have max and min functions ignore None

Andrew Barnert abarnert at yahoo.com
Tue Dec 29 00:43:23 EST 2015


On Dec 28, 2015, at 20:08, Franklin? Lee <leewangzhong+python at gmail.com> wrote:
> 
> This change would allow one to use `None` as a default value.

Actually, it might be useful to allow a default value in general. (In typed functional languages, you often specify a default, or use a type that has a default value, so max(list[A]) can always return an A.)

Then again, you can write this pretty easily yourself:

    def my_max(iterable, *, default=_sentinel):
        try:
            return max(Iterable)
        except WhateverEmptyIterableRaises:
            if default is _sentinel: raise
            return default



More information about the Python-ideas mailing list