SyntaxFix
Write A Post
Hire A Developer
Questions
Tags
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?
This question is related to python sorting
python
sorting
my_list = sorted(dict.items(), key=lambda x: x[1])
[v[0] for v in sorted(foo.items(), key=lambda(k,v): (v,k))]
I like this one:
sorted(d, key=d.get)
Source: Stackoverflow.com