[Python-ideas] list.sort with a int or str key
raymond.hettinger at gmail.com
Fri Sep 17 11:04:04 CEST 2010
>> ISTM, the performance would be about the same as you already get from attrgetter(), itemgetter(), and methodcaller(). Also, those three tools are already more flexible than the proposal, for example:
>> attrgetter('lastname', 'firstname') # key = lambda r: (r.lastname, r.firstname)
>> itemgetter(0, 7) # key = lambda r: (r, r)
>> methodcaller('get_stats', 'size') # key = lambda r: r.get_stats('size')
> It is easy to not know about these.
FWIW, those and other sorting related topics are covered in the sorting-howto:
We link to that from the main docs for sorted():
> I think the doc set could usefully use an expanded entry on *key functions*
That might also make a useful entry to the glossary.
P.S. I don't know that it applies here but one limitation of the docs
is that they can get too voluminous. Already, it is a significant time
investment just to read the doc page on builtin functions. You can
kill a whole afternoon just reading the docs for unittest and logging.
The gestalt of the language gets lost when the docs get too fat.
Instead, I like the howto write-ups because they bring together many
thoughts on a single topic.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas