Why are there no ordered dictionaries?
bokr at oz.net
Tue Nov 22 19:32:18 CET 2005
On Tue, 22 Nov 2005 10:26:22 +0100, Christoph Zwerschke <cito at online.de> wrote:
>Bengt Richter wrote:
> > d = OrderedDict(); d='one'; d='two' =>> list(d) => [1, 2]
> > ok, now we do d='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?
More information about the Python-list