+ 1
How to sort these words?
6 Answers
+ 2
Use sorted() with key parameter.
print(json.dumps({k: v for k, v in sorted(d.items(), key=lambda item: item[1])}, indent=1))
+ 3
Hel Azot add reverse parameter and pass True to it.
sorted(d.items(), key=lambda item: item[1], reverse=True)
+ 1
if d.items() is a list, d.items()[::-1] is that list backwards
+ 1
CarrieForle thanks, it works perfectly!
0
CarrieForle thanks! But do you have an idea how to make it it start from the biggest number not the smallest?
Like
16
14
13
7
1
Etc
0
Slick it seems not to work, but thank you