<div dir="ltr">Antoine, my concern is not efficiency but convenience. Whoever has high efficiency requirements and wants to sort an ordered dict will have to find their own solution anyway, and the other 99% of people who just want to sort a 20-items-long ordered dict in their small web app could happily use `OrderedDict.sort`.<div>

<br></div><div>And while we're on that subject, can we also add `OrderedDict.index`?<br><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Sep 24, 2013 at 3:29 PM, Antoine Pitrou <span dir="ltr"><<a href="mailto:solipsis@pitrou.net" target="_blank" onclick="window.open('https://mail.google.com/mail/?view=cm&tf=1&to=solipsis@pitrou.net&cc=&bcc=&su=&body=','_blank');return false;">solipsis@pitrou.net</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class="im">On Tue, 24 Sep 2013 22:13:15 +1000<br>
Steven D'Aprano <<a href="mailto:steve@pearwood.info" onclick="window.open('https://mail.google.com/mail/?view=cm&tf=1&to=steve@pearwood.info&cc=&bcc=&su=&body=','_blank');return false;">steve@pearwood.info</a>> wrote:<br>


> On Tue, Sep 24, 2013 at 04:49:20AM -0700, Ram Rachum wrote:<br>
> > What do you think about providing an `OrderedDict.sort` method? I've been<br>
> > using my own `OrderedDict` subclass that defines `sort` for years, and I<br>
> > always wondered why the stdlib one doesn't provide `sort`.<br>
> ><br>
> > I can write the patch if needed.<br>
><br>
> I'm not entirely sure why anyone would need an OrderedDict sort method.<br>
> Ordered Dicts store keys by insertion order. Sorting the keys goes<br>
> against the purpose of an OrderedDict.<br>
<br>
</div>An OrderedDict is basically an associative container with a<br>
well-defined ordering. It's not only "insertion order", because you can<br>
use move_to_end() to reorder it piecewise.<br>
(at some point I also filed a feature request to rotate an OrderedDict:<br>
 <a href="http://bugs.python.org/issue17100" target="_blank">http://bugs.python.org/issue17100</a>)<br>
<br>
However, sorting would be difficult to implement efficiently with the<br>
natural implementation of an OrderedDict, which uses linked lists.<br>
Basically, you're probably as good sorting the items separately and<br>
reinitializing the OrderedDict with them.<br>
<br>
Regards<br>
<span class=""><font color="#888888"><br>
Antoine.<br>
</font></span><div class=""><div class="h5"><br>
<br>
_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org" onclick="window.open('https://mail.google.com/mail/?view=cm&tf=1&to=Python-ideas@python.org&cc=&bcc=&su=&body=','_blank');return false;">Python-ideas@python.org</a><br>


<a href="https://mail.python.org/mailman/listinfo/python-ideas" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
<br>
--<br>
<br>
---<br>
You received this message because you are subscribed to a topic in the Google Groups "python-ideas" group.<br>
To unsubscribe from this topic, visit <a href="https://groups.google.com/d/topic/python-ideas/-RFTqV8_aS0/unsubscribe" target="_blank">https://groups.google.com/d/topic/python-ideas/-RFTqV8_aS0/unsubscribe</a>.<br>
To unsubscribe from this group and all its topics, send an email to <a href="mailto:python-ideas%2Bunsubscribe@googlegroups.com" onclick="window.open('https://mail.google.com/mail/?view=cm&tf=1&to=python-ideas%2Bunsubscribe@googlegroups.com&cc=&bcc=&su=&body=','_blank');return false;">python-ideas+unsubscribe@googlegroups.com</a>.<br>


For more options, visit <a href="https://groups.google.com/groups/opt_out" target="_blank">https://groups.google.com/groups/opt_out</a>.<br>
</div></div></blockquote></div><br></div></div></div>