Delsin Delsin - 6 months ago 8
Python Question

How to sort keys of dict by values?

I have a dict

{'a': 2, 'b': 0, 'c': 1}
.

Need to sort keys by values so that I can get a list
['b', 'c', 'a']


Is there any easy way to do this?

Answer
 sorted_keys = sorted(my_dict, key=my_dict.get)