3/30
Part 1 of 7 · Score orderLearn and do

reverse=True reverses the tie-break too

The first fix most people try keeps reverse=True and adds the title to the key:

print(sorted(CATALOG, key=lambda title: (CATALOG[title], title), reverse=True))
['Comet', 'Maple', 'Harbor', 'Orbit', 'Tundra']

Maple still comes before Harbor, and now for a different reason. reverse=True reverses the whole comparison, the title included, so ties come out in reverse alphabetical order. It passes every test without a tie and fails the first one with a tie.

There's a second correct way, and it explains why the sort is built the way it is. Python's sorting guide says the reverse parameter still maintains sort stability: equal keys keep their order. So you can sort twice. First sort by the tie-break, then sort by score with reverse=True. The second sort decides the order, and wherever two scores are equal, the stable sort keeps the alphabetical order the first pass left.

titles = sorted(CATALOG)
titles.sort(key=lambda title: CATALOG[title], reverse=True)
print(titles)
['Comet', 'Harbor', 'Maple', 'Orbit', 'Tundra']

The rule to remember: the last sort is the main order, and each earlier sort only settles ties. Two passes help when one key can't express both orders, such as a descending string after an ascending number.

The editor holds a rank that sorts twice, with the two passes in the wrong order. Run it on the tie it prints, then fix rank by swapping the passes.