7th Apr 2021, 11:49 AM
Hel Azot
Hel Azot - avatar
6 Respuestas
+ 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))
7th Apr 2021, 12:04 PM
你知道規則,我也是
你知道規則,我也是 - avatar
+ 3
Hel Azot add reverse parameter and pass True to it. sorted(d.items(), key=lambda item: item[1], reverse=True)
7th Apr 2021, 1:03 PM
你知道規則,我也是
你知道規則,我也是 - avatar
+ 1
if d.items() is a list, d.items()[::-1] is that list backwards
7th Apr 2021, 12:49 PM
Slick
Slick - avatar
+ 1
CarrieForle thanks, it works perfectly!
7th Apr 2021, 1:05 PM
Hel Azot
Hel Azot - avatar
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
7th Apr 2021, 12:09 PM
Hel Azot
Hel Azot - avatar
0
Slick it seems not to work, but thank you
7th Apr 2021, 12:55 PM
Hel Azot
Hel Azot - avatar