Fix Python – Sorting dictionary keys in python [duplicate]


Asked By – George

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?

Now we will see solution for issue: Sorting dictionary keys in python [duplicate]


>>> mydict = {'a':1,'b':3,'c':2}
>>> sorted(mydict, key=lambda key: mydict[key])
['a', 'c', 'b']

This question is answered By – Markus Jarderot

This answer is collected from stackoverflow and reviewed by FixPython community admins, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0