I have a dictionary:
a = {\'100\':12,\'6\':5,\'88\':3,\'test\':34, \'67\':7,\'1\':64 }
I want to sort this dictionary with respect to key s
If you install my blist package, it includes a sorteddict type. Then you could simply:
from blist import sorteddict
def my_key(dict_key):
try:
return int(dict_key)
except ValueError:
return dict_key
a = {'100':12,'6':5,'88':3,'test':34, '67':7,'1':64 }
print sorteddict(my_key, **a).keys()
Output:
['1', '6', '67', '88', '100', 'test']