[Python-Dev] argmax? (original) (raw)
Alex Martelli aleaxit at yahoo.com
Thu Jan 8 15:50:00 EST 2004
- Previous message: [Python-Dev] argmax?
- Next message: [Python-Dev] Re: [Python-checkins] python/dist/src/Doc/lib libstdtypes.tex, 1.149, 1.150
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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...!
Alex
- Previous message: [Python-Dev] argmax?
- Next message: [Python-Dev] Re: [Python-checkins] python/dist/src/Doc/lib libstdtypes.tex, 1.149, 1.150
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]