[Python-Dev] Proposal: add odict to collections

Nick Coghlan ncoghlan at gmail.com
Sun Jun 15 07:25:31 CEST 2008


Talin wrote:
> Michael Foord wrote:
>> Armin Ronacher wrote:
>>> Hi,
>>>
>>> I noticed lately that quite a few projects are implementing their own
>>> subclasses of `dict` that retain the order of the key/value pairs.
>>> However half of the implementations I came across are not implementing
>>> the whole dict interface which leads to weird bugs, also the performance
>>> of a Python implementation is not that great.
>>>
>>>   
>>
>> I'm +1 - but this proposal has been made many times before and people 
>> always argue about what features are needed or desirable. :-(
> 
> There's been a lot of controversy/confusion about ordered dicts. One of 
> the sources of confusion is that people mean different things when they 
> use the term "ordered dict": In some cases, the term is used to mean a 
> dictionary that remembers the order of insertions, and in other cases it 
> is used to mean a sorted dict, i.e. an associative data structure in 
> which the entries are kept sorted. (And I'm not sure that those are the 
> only two possibilities.)
> 
> I would be more in favor of the idea if we could come up with a less 
> ambiguous naming scheme.

I think Armin's proposal addresses this nicely by the analogy to lists: 
the ordered dict is in key insertion order by default, but you can 
invoke odict.sort() to sort it instead.

Given the synergy with the Py3k metaclass enhancements, I believe this 
would be a good thing to have.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://www.boredomandlaziness.org


More information about the Python-Dev mailing list