Why are there no ordered dictionaries?

Christoph Zwerschke cito at online.de
Wed Nov 23 15:56:57 EST 2005


Ganesan Rajagopal wrote:

> the definition of "sorted" and "ordered", before we can > go on ? Sorted 
> would be ordered by key comparison. Iterating over such a container will 
> give you the keys in sorted order. Java calls this a SortedMap. See 
> http://java.sun.com/j2se/1.4.2/docs/api/java/util/SortedMap.html C++ STL 
> map container is also a Sorted Associative container. See 
> http://www.sgi.com/tech/stl/Map.html  Ganesan

Exactly, that's "sorted." "Ordered" means the same there is some order 
between the existing elements, but there is no magic (i.e. a general 
comparison function) for ordering new elements. Thus, if you add an 
element to an ordered collection, it simply gets appended (is considered 
as the greatest of all elements) by convention, whereas if you add an 
element to a sorted collection, it will be inserted into the correct 
place by using the comparison function.

-- Christoph



More information about the Python-list mailing list