[issue18111] Add a default argument to min & max

Julian Berman report at bugs.python.org
Sun Jun 2 03:42:06 CEST 2013


Julian Berman added the comment:

Thanks for finding that, I thought there was an issue that came out of that p-i thread but couldn't find it.

I'd like to be more concrete, but "calling max on an iterable" seems concrete enough to me. If you'd like to know more though, personally I've wanted this at least twice in the past 4 or 5 months. Currently, I have code that looks like:

    def best_match(stuff):
        first = next(stuff, None)
        if first is None:
            return
        return max(itertools.chain([first], stuff))

which finds the best matching (error it happens to be) in the given stuff. A few months ago I had a similar need in a different application.

The issues in that thread from 2009 revolved around a bunch of confusing and not so related things. And I definitely agree that `start` is a really bad name for this. But I don't find `default` to be at all confusing, and in fact this has come up in #python a few times and each time there hasn't really been a problem explaining to someone what `default` would do (or how it would interact with `key` for that matter, although if a precedent is desired, the default in `argparse` just returns the default, it doesn't call `type` or anything on it).

----------

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


More information about the Python-bugs-list mailing list