This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Brian.Mearns
Recipients Brian.Mearns
Date 2014-12-02.14:25:37
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1417530338.57.0.34442889749.issue22979@psf.upfronthosting.co.za>
In-reply-to
Content
`None` should never be the result of the built-in `min` and `max` functions. When `None` is supplied as one of the values to check, it should never be chosen as the result.

This would make it much easier to find a minimum and/or maximum while iterating over values. For instance, the following is a common pattern:

    mn = None
    mx = None
    for x in iterable:
        if mn is None or x < mn:
            mn = x
        if mx is None or x > mx:
            mx = x

Note that although the `min` and `max` functions could be applied directly to `iterable` in the above case, the above pattern is more efficient (only once through the loop) and covers the common case where additional operations are performed on each value of the iterable.

If the suggested enhancement was made, the above code could be written more simply as:

    mn = None
    mx = None
    for x in iterable:
        mn = min(mn, x)
        mx = max(mx, x)

At present, this will actually work for `max`, as None evaluates as less than every number, but it will not work for `min` (for the same reason).

The suggested change would mean that None is simultaneously greater than and less than every other value, but that only matters if we assume a total ordering of all the values including None, which doesn't seem like it would be important.
History
Date User Action Args
2014-12-02 14:25:38Brian.Mearnssetrecipients: + Brian.Mearns
2014-12-02 14:25:38Brian.Mearnssetmessageid: <1417530338.57.0.34442889749.issue22979@psf.upfronthosting.co.za>
2014-12-02 14:25:38Brian.Mearnslinkissue22979 messages
2014-12-02 14:25:37Brian.Mearnscreate