Ddude
Ddude

Reputation: 61

How do I make the tuple order the opposite way around?

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

Answers (1)

vks
vks

Reputation: 67968

highestList = sorted(classFile.items(), key=lamda x: x[::-1],reverse=True)

Use reverse=True

Upvotes: 1

Related Questions