Why are there no ordered dictionaries?

Christoph Zwerschke cito at online.de
Tue Nov 22 04:26:22 EST 2005


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?

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.

-- Christoph



More information about the Python-list mailing list