12/30
Part 3 of 7 · Two sorted listsLearn and do

Find the bug: a title that shows twice in one loop

This one looks right, and it passes a test where every title is new. Then a score changes and a title shows twice.

The order of two lines decides it. The old key is built from scores[title]. Overwrite the score first and the "old" key is really the new key. The search doesn't find it, nothing is deleted, and the real old key stays in its list next to the new one. Now the title is in the billboard twice, and get will show both.

A test with a known title catches it. So does printing the lists after one update and counting the keys. Five titles should mean five keys.

The editor holds an update with one line in the wrong place. Run it, read waiting in what it prints, and move the line in update so the old key is removed.