Possible Duplicate:
Ordering in Python (2.4) dictionary
I tried to copy a dict to another but in a sorted way. I got the follwing problem.
mydict = {'carl':40,
'alan':2,
'bob':1,
'danny':3}
d1={}
for key in sorted(mydict):
d1[key]=mydict[key]
When I print d1 it shows:
{'bob': 1, 'danny': 3, 'carl': 40, 'alan': 2}
Why is it not in sorted order?
Dicts have no order.
You have to use a OrderedDict.