I'm using Python 3.8. I am trying to sort players by points (in descending order) and then, only if they have the same number of points, by rank.
I've already read Sorting HOW TO, Python sorting by multiple criteria and Sorting by multiple conditions in python.
Here's my code:
from operator import itemgetter
players_results = [
("Pierre", 1.0, 1),
("Matthieu", 1.0, 2),
("Joseph", 0.5, 3),
("Marie", 0.0, 4),
("Michel", 0.5, 5),
("Raphael", 0.0, 6),
]
sorted_by_points = sorted(players_results, key=itemgetter(1), reverse=True)
points_descending_rank_ascending = sorted(sorted_by_points, key=itemgetter(2))
print(points_descending_rank_ascending)
# [('Pierre', 1.0, 1), ('Matthieu', 1.0, 2), ('Joseph', 0.5, 3), ('Marie', 0.0, 4), ('Michel', 0.5, 5), ('Raphael', 0.0, 6)]
In each tuple, the number of points are of float type while the rank is of integer type. My problem is that Michel should be before Marie, but that's not the case. Can someone explain what I have to implement differently?