That is because the keyword arguments (variable = value, )
that you pass will be consolidated into a Python dictionary first. And Python dictionaries are unordered. kwds
will be that dictionary as you can see in the Init signature.
Init signature: OrderedDict(self, *args, **kwds)
This is how the OrderedDict will be initialized internally when you pass the keyword arguments:
for key, value in kwds.items():
self[key] = value
Since kwds
is unordered, you will get an unordered OrderedDict.
You may create the ordered dict like so:
from collections import OrderedDict
from string import ascii_lowercase
d = OrderedDict()
for a,b in enumerate(ascii_lowercase[:3], 1):
d[b] = a
Or:
n=3
d = OrderedDict(zip(ascii_lowercase[:n], range(1,n+1)))
print d
Output:
OrderedDict([('a', 1), ('b', 2), ('c', 3)])