Skip to content
scipython.com

Q2.4.3Ranking a list

Given an ordered list of test scores, produce a list associating each score with a rank (starting with 1 for the highest score). Equal scores should have the same rank. For example, the input list [87, 75, 75, 50, 32, 32] should produce the list of rankings [1,2,2,4,5,5].

Show solution

Here is one solution:

>>> scores = [87, 75, 75, 50, 32, 32]
>>> ranks = []
>>> for score in scores:
...     ranks.append(scores.index(score) + 1)
...
>>> ranks
[1, 2, 2, 4, 5, 5]