爲什麼我的python OrderedDict得到'失序'初始化?Python OrderedDict迭代
這裏的解決方案比解釋更不耐人尋味。這裏有些東西我沒有得到,也許一個膨脹會幫助別人和我一樣。
>>> from collections import OrderedDict
>>> spam = OrderedDict(s = (1, 2), p = (3, 4), a = (5, 6), m = (7, 8))
>>> spam
OrderedDict([('a', (5, 6)), ('p', (3, 4)), ('s', (1, 2)), ('m', (7, 8))])
>>> for key in spam.keys():
... print key
...
# this is 'ordered' but not the order I wanted....
a
p
s
m
# I was expecting (and wanting):
s
p
a
m
「kwargs」未訂購。 – georg
[轉換字典爲OrderedDict]可能的重複(http://stackoverflow.com/questions/15711755/converting-dict-to-ordereddict) –