How can I sort tuples by reverse, yet breaking ties non-reverse? (Python)
If I have a list of tuples:
results = [('10', 'Mary'), ('9', 'John'), ('10', 'George'), ('9',
'Frank'), ('9', 'Adam')]
How can I sort the list as you might see in a scoreboard - such that it
will sort the score from biggest to smallest, but break ties
alphabetically by name?
So after the sort, the list should look like:
results = [('10', 'George'), ('10', 'Mary'), ('9', 'Adam'), ('9',
'Frank'), ('9', 'John')]
At the moment all I can do is results.sort(reverse=True), but breaks ties
reverse alphabetically too...
Any help would be much appreciated. Thanks!
No comments:
Post a Comment