Delsin Delsin - 1 year ago 68
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 Source
 sorted_keys = sorted(my_dict, key=my_dict.get)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download