Warum wird mein Python OrderedDict initialisiert 'out of order'?Python OrderedDict Iteration
Die Lösung hier ist weniger faszinierend als die Erklärung. Es gibt etwas hier, das ich einfach nicht verstehe, und vielleicht würde eine Erweiterung anderen genauso helfen wie mir.
>>> 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" sind nicht bestellt. – georg
Mögliches Duplikat von [Konvertierung von dict nach OrderedDict] (http://stackoverflow.com/questions/15711755/converting-dict-to-ordereddict) –