The dictionary makes no sense in ordering, so your key / value pairs are not ordered in any format.
If you want to preserve the order of the keys, you should use collections.OrderedDict from the beginning, instead of the usual dictionary, Example -
>>> from collections import OrderedDict >>> d = OrderedDict([('a',1),('b',2),('c',3)]) >>> d OrderedDict([('a', 1), ('b', 2), ('c', 3)])
OrderedDict will keep the order in which keys were entered into the dictionary. In the above case, this would be the order in which the keys existed in the list - [('a',1),('b',2),('c',3)] - 'a' -> 'b' -> 'c'
Then you can get the reverse order of the keys with reversed(d) , Example -
>>> dreversed = OrderedDict() >>> for k in reversed(d): ... dreversed[k] = d[k] ... >>> dreversed OrderedDict([('c', 3), ('b', 2), ('a', 1)])
source share