Possible Duplicate:
Python: Sort a dictionary by value
I have a dictionary like this:
A = {'Name1':34, 'Name2': 12, 'Name6': 46,....}
I want a list of keys sorted by the values, i.e. [Name2, Name1, Name6....]
Thanks!!!
Use sorted
with the get
method as a key (dictionary keys can be accessed by iterating):
sorted(A, key=A.get)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With