I have a dict where each key references an int value. What's the best way to sort the keys into a list depending on the values?
+15
A:
>>> mydict = {'a':1,'b':3,'c':2}
>>> sorted(mydict, key=lambda key: mydict[key])
['a', 'c', 'b']
MizardX
2009-02-22 21:21:22
thanks, Brian R. Body. :)
MizardX
2009-02-22 21:26:30
Bondy* ... can't spell tody
MizardX
2009-02-22 21:29:06