Reputation: 61
I am relatively new to python so I need some help to setup my highest to lowest sorting system for a dictionary. I use:
highestList = sorted(classFile.items(), key=lamda x: x[::-1])
This sorted my dictionary into a tuple but it is the wrong way around. it outputs:
[('Dylan', 4), ('Jimmy', 5), ('Mark', 5), ('Chris', 7)]
Where I would like it to output:
[('Chris', 7), ('Mark', 5), ('Jimmy',5), ('Dylan',4)]
Upvotes: 2
Views: 74
Reputation: 67968
highestList = sorted(classFile.items(), key=lamda x: x[::-1],reverse=True)
Use reverse=True
Upvotes: 1