I'm trying to sort this dictionary a
by the key alphabetically. I'm looping through in order, but the dictionary c
at the end isn't sorted. I don't understand how python assigns the order of the dictionary key. Why does it maintain the original order? and how do I sort by key alphabetically?
a={'BE': 1, 'BC': 2, 'BO': 3, 'BI': 4, 'BK': 5, 'AQ': 6, 'AS': 7, 'BQ': 8, 'AW': 9, 'AY': 10}
b=sorted(a)
c={}
for i in b:
print i
c[i]=a[i]
I'm using python 2.7