[Python-Dev] adding key argument to min and max
steven.bethard at gmail.com
Thu Dec 2 02:02:33 CET 2004
Raymond Hettinger <python at rcn.com> wrote:
> [Steven Bethard]
> > For Python 2.5, I'd like to add a keyword argument 'key' to min and
> > max like we have now for list.sort and sorted.
> . . .
> > This means that a 'key'
> > argument can *only* be specified as a keyword parameter, thus giving
> > us the asymmetry we see in these examples.
> FWIW, in Py2.5 I plan on adding a key= argument to heapq.nsmallest() and
> heapq.nlargest(). There is no "assymmetry" issue with those functions,
> so it can be implemented cleanly. And, since min/max are essentially
> the same nsmallest/nlargest with n==1, your use case is covered and
> there is no need to mess with the min/max builtins.
I don't want to put words into your mouth, so is this a vote against a
key= argument for min and max?
If nsmallest/nlargest get key= arguments, this would definitely cover
the same cases. If a key= argument gets vetoed for min and max, I'd
at least like to add a bit of documentation pointing users of min/max
to nsmallest/nlargest if they want a key= argument...
You can wordify anything if you just verb it.
--- Bucky Katt, Get Fuzzy
More information about the Python-Dev