[Python-ideas] list.sort with a int or str key

Daniel Stutzbach daniel at stutzbachenterprises.com
Thu Sep 16 17:35:14 CEST 2010

list.sort, sorted, and similar methods currently have a "key" argument that
accepts a callable.  Often, that leads to code looking like this:

mylist.sort(key=lambda x: x[1])
myotherlist.sort(key=lambda x: x.length)

I would like to propose that the "key" parameter be generalized to accept
str and int types, so the above code could be rewritten as follows:


I find the latter to be much more readable.  As a bonus, performance for
those cases would also improve.
Daniel Stutzbach <http://stutzbachenterprises.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20100916/5f43c1ee/attachment.html>

More information about the Python-ideas mailing list