Storing Python dictionary entries in the order they are pushed [duplicate]
Try python 2.7 and above, probably 3.1, there is OrderedDict
http://python.org/download/releases/2.7/
>>> from collections import OrderedDict>>> d = OrderedDict([('first', 1), ('second', 2),... ('third', 3)])>>> d.items()[('first', 1), ('second', 2), ('third', 3)]
Implementations of order-preserving dictionaries certainly do exist.
There is this one in Django, confusingly called SortedDict
, that will work in Python >= 2.3 iirc.