I am trying to sort a dictionary by key.
If I do the following, then the dictionary is sorted like this
1, 20
10, 5
11, 3
2, 30
20, 2
Instead, I wanted to sort it like the following:
1, 20
2, 30
10, 5
11, 3
20, 2
My existing code
writer = csv.writer(open('something.csv', 'wb'))keylist = count.keys()
keylist.sort()
for key in keylist:writer.writerow([key, count[key]])