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', 4)
('five', 5)
I need to write as I read the dictionary. Any ideas to achieve this in Python 2.6?
It seems that you want an ordered dictionary. If you can use Python 2.7, look up
collections.OrderedDict: https://docs.python.org/2/library/collections.html#collections.OrderedDictIf you have to stick with 2.6, there are some suggestions here: https://stackoverflow.com/a/1617087/3061818 (but you should probably head over to Dictionaries: How to keep keys/values in same order as declared?)