Why are there no ordered dictionaries?

Bengt Richter bokr at oz.net
Tue Nov 22 13:32:18 EST 2005


On Tue, 22 Nov 2005 10:26:22 +0100, Christoph Zwerschke <cito at online.de> wrote:

>Bengt Richter wrote:
>
> > d = OrderedDict(); d[1]='one'; d[2]='two' =>> list(d) => [1, 2]
> > ok, now we do d[1]='ein' and what is the order? list(d) => [2, 1] ??
> > Or do replacements not count as "insertions"?
>
>If you simply set a value for a key that already exists, the order 
>should not be changed. I think this is intuitive.
>
>>  Or maybe you want to permit append and NOT prevent
> > [('a',1), ('a':2)] and maybe d['a'] => [1, 2] ???
>
>You could ask the same question about dict. I think that is not an 
>option. Why should you want odict behave different than dict?
Well, it was beginning to remind of RDB with possible non-unique keys,
where a select can get you multiple records back.
>
>I still believe that the concept of an "ordered dictionary" ("behave 
>like dict, only keep the order of the keys") is intuitive and doesn't 
>give you so much scope for ambiguity. But probably I need to work on an 
>implementation to become more clear about possible hidden subtleties.
>
Does that mean that the Larosa/Foord odict.py implementation in PyPI
does not do what you want?

Regards,
Bengt Richter



More information about the Python-list mailing list