Why are there no ordered dictionaries?

Bengt Richter bokr at oz.net
Wed Nov 23 03:48:18 CET 2005


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

>> d1[0:0] + d1[2:2] ==> OrderedDict( (1, 11), (3, 13) )
>
>Oops, sorry, that was nonsense again. I meant
>d1[0:1] + d1[1:2] ==> OrderedDict( (1, 11), (3, 13) )
>
>> Ordered dictionaries could allow slicing and concatenation.
>
>Some operations such as concatenation need of course special 
>considerations, since the keys must stay unique. A concatenation of 
>ordered dicts with overlapping keys should probably give an IndexError.
>
If you define the semantics like feeding overlapping keys in a tuple
sequence to dict, then later duplicate keys just replace prior ones
by same rules as d[k]=v1; d[k]=v2. I think that makes sense in this
context, and can be defined unambigously.

Regards,
Bengt Richter



More information about the Python-list mailing list