8/13
Part 2 of 4 · Three moves you'll use everywhereLearn and do

Sort with a key, and break ties on purpose

sorted takes a key: a function that turns each item into the value to sort by. A tuple key sorts by its first part, then breaks ties with the second:

players = [("ana", 90), ("ben", 75), ("cy", 90), ("dee", 60)]
print(sorted(players, key=lambda p: p[1]))
print(sorted(players, key=lambda p: (-p[1], p[0])))
[('dee', 60), ('ben', 75), ('ana', 90), ('cy', 90)]
[('ana', 90), ('cy', 90), ('ben', 75), ('dee', 60)]

The minus sign puts the highest scores first, and the name breaks a tie from A to Z. Don't reach for reverse=True here: it reverses the whole key, the names included, so ties come out from Z to A.

In the editor, write top_k(scores, k): the names with the k highest scores.