ram at rachum.com
Tue Sep 24 14:50:08 CEST 2013
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
And while we're on that subject, can we also add `OrderedDict.index`?
On Tue, Sep 24, 2013 at 3:29 PM, Antoine Pitrou <solipsis at pitrou.net> wrote:
> On Tue, 24 Sep 2013 22:13:15 +1000
> Steven D'Aprano <steve at pearwood.info> wrote:
> > On Tue, Sep 24, 2013 at 04:49:20AM -0700, Ram Rachum wrote:
> > > What do you think about providing an `OrderedDict.sort` method? I've
> > > using my own `OrderedDict` subclass that defines `sort` for years, and
> > > always wondered why the stdlib one doesn't provide `sort`.
> > >
> > > I can write the patch if needed.
> > I'm not entirely sure why anyone would need an OrderedDict sort method.
> > Ordered Dicts store keys by insertion order. Sorting the keys goes
> > against the purpose of an OrderedDict.
> An OrderedDict is basically an associative container with a
> well-defined ordering. It's not only "insertion order", because you can
> use move_to_end() to reorder it piecewise.
> (at some point I also filed a feature request to rotate an OrderedDict:
> However, sorting would be difficult to implement efficiently with the
> natural implementation of an OrderedDict, which uses linked lists.
> Basically, you're probably as good sorting the items separately and
> reinitializing the OrderedDict with them.
> Python-ideas mailing list
> Python-ideas at python.org
> You received this message because you are subscribed to a topic in the
> Google Groups "python-ideas" group.
> To unsubscribe from this topic, visit
> To unsubscribe from this group and all its topics, send an email to
> python-ideas+unsubscribe at googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas