Why are there no ordered dictionaries?

Christoph Zwerschke cito at online.de
Mon Nov 21 17:54:18 CET 2005

Ben Finney wrote:

 >>> Another possibility: ordered dictionaries are not needed when Python
 >>> 2.4 has the 'sorted' builtin.

Christoph Zwerschke wrote:

 >> The 'sorted' function does not help in the case I have indicated,
 >> where "I do not want the keys to be sorted alphabetically, but
 >> according to some criteria which cannot be derived from the keys
 >> themselves."

Mike Meyer wrote:

 > And how would an ordered dictionary help in this case?

Maybe there is some confusion between an "orderable" and an "ordered" 
dictionary. When I talk about "ordered dictionary", then in the simplest 
case I just set up my ordered dictionary with my preferred key order and 
it stays like that. This allows me to later iterate through the 
dictionary in this preferred order, while being still able to randomly 
access data from the dictionary at other places.

-- Christoph

More information about the Python-list mailing list