[Python-Dev] argmax?

Alex Martelli aleaxit at yahoo.com
Thu Jan 8 15:50:00 EST 2004

On Thursday 08 January 2004 06:59 pm, Josiah Carlson wrote:
> I don't know how anyone would feel about adding it to the standard
> library,

Personally, I have thought for quite a while that max and min should grow a 
key= optional keyword argument, just like the sort method of list objects now 
has in 2.4.  Admittedly not quite equivalent to the argmax function proposed 
(or to your itertools-based solution), but IMHO preferable -- because 
somelist.sort will now allow just that shortcut to the typical "D-S-U" idiom 
(if one wants the values as well as the underlying items, then an explicit 
D-S-U [or however you want to name it when applied to min and max...] can of 
course still perfectly well be performed, for somelist.sort as well as for 
min and max).  When one has grown used to somelist.sort(key=foobar),
having e.g. min(somelist, key=foobar) [for those cases in which one only needs 
to know the item x of somelist which has minimal foobar(x), rather than the 
whole somelist-ordered-by-foobar()] is just SUCH natural usage, IMHO...!


More information about the Python-Dev mailing list