Print dict iteration elements as it is read(declared) [duplicate]
-1
This question already has an answer here:
Dictionaries: How to keep keys/values in same order as declared?
11 answers
I am reading a dictionary in python2.6 as below I know Python3.6 will read the dictionary in the same order it is declared, but i need to achieve this in Python2.6 (OrderedDict is also not available in Python2.6) numbermap = {'one': 1, 'two': 2, 'three': 3, 'four': 4, 'five': 5} >>> for k, v in numbermap.iteritems(): ... print(k,v) ... ('four', 4) ('three', 3) ('five', 5) ('two', 2) ('one', 1) I want the output to be ('one',1) ('two', 2) ('three', 3) ('four