Why are there no ordered dictionaries?

Alex Martelli aleax at mail.comcast.net
Tue Nov 22 21:35:23 EST 2005


Christoph Zwerschke <cito at online.de> wrote:
   ...
> * C++ has a Map template in the STL which is ordered (a "Sorted 
> Associative Container").

Ordered *by comparisons on keys*, NOT by order of insertion -- an
utterly and completely different idea.

> So ordered dictionaries don't seem to be such an exotic idea.

Ordered *by order of key insertion*: Java, PHP
Ordered *by other criteria*: LISP, C++
Unordered: Python, Perl, Ruby, Smalltalk, Awk, Tcl

by classification of the languages you've listed.

> I can't help but I still find it unambiguous and intuitive enough to 
> consider it "the one" standard implementation for ordered dictionaries.

Then you should be very careful not to call C++'s implementation
"ordered", because that makes it VERY HARD to argue that "the one"
thingy;-).

Nevertheless, since sorting by keys (or any function of the keys and
values, including one depending on an external table, which was claimed
to be otherwise in other parts of this thread) is so trivial, while
recovering insertion order is impossible without some auxiliary data
structure ``on the side'', I agree that a dictionary subclass that's
ordered based on insertion timing would have more added value than one
where the 'ordering' is based on any function of keys and values.


Alex



More information about the Python-list mailing list