我正在 python2.6 中阅读字典,如下所示我知道 Python3.6 将按照声明的顺序读取字典,但我需要在 Python2.6 中实现这一点(OrderedDict 在 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)
我希望输出是
('one',1)
('two', 2)
('three', 3)
('four', 4)
('five', 5)
我需要边看字典边写。在 Python 2.6 中实现这一点的任何想法?