-1<div><br></div><div>key='length' could reasonably mean</div><div>    lambda a:a.length</div><div>or</div><div>    lambda a:a['length']</div><div><br><div>an explicit lambda or itemgetter/attrgetter is clearer.</div>

<div><br clear="all">--- Bruce<br><a href="http://www.vroospeak.com" target="_blank">http://www.vroospeak.com</a><br><a href="http://j.mp/gruyere-security" target="_blank">http://j.mp/gruyere-security</a><br><br>
<br><br><div class="gmail_quote">On Thu, Sep 16, 2010 at 8:35 AM, Daniel Stutzbach <span dir="ltr"><<a href="mailto:daniel@stutzbachenterprises.com">daniel@stutzbachenterprises.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

list.sort, sorted, and similar methods currently have a "key" argument that accepts a callable.  Often, that leads to code looking like this:<br><br>mylist.sort(key=lambda x: x[1])<br>
myotherlist.sort(key=lambda x: x.length)<br><br>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:<br><br>mylist.sort(key=1)<br>


myotherlist.sort(key='length')<br><br>I find the latter to be much more readable.  As a bonus, performance for those cases would also improve.<br><div style="margin:2em 0pt" name="sig_2341e11ee1">--<br><font color="#888888">
Daniel Stutzbach<a href="http://stutzbachenterprises.com" target="_blank"></a>
</font></div>
<br>_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/python-ideas" target="_blank">http://mail.python.org/mailman/listinfo/python-ideas</a><br>
<br></blockquote></div><br></div></div>