9/28
Part 2 of 6 · Filling a rowLearn and do
After the screen, the rest of the row follows in its order
The screen takes a few titles from a row. The rest still belong in the row, because the viewer can scroll it. Q-nfx-048 says it directly: past the first n positions, a row only has to avoid repeating itself.
So the row's rest is every title not in the head, in the row's original order, each once. The titles skipped for the screen come back here, in their place:
row, head = ["B", "A", "D", "E"], ["D", "E"]
rest = [t for t in dict.fromkeys(row) if t not in head]
print(head + rest)
['D', 'E', 'B', 'A']
B and A were on the screen in row 0, so row 1 couldn't show them up front. Past the screen they're fine, and they keep the order the ranker gave them.
Three ways to get this wrong, each of them easy to write:
head + row[len(head):], cutting at the head's length. That assumes the head was the row's first titles. Here it would add E again and lose B and A.[t for t in row if t not in head]keeps a title the row lists twice.- Sorting the rest throws away the ranking, the one thing the row's order is for.
In the editor, write finish_row(row, head): the head, then every other title of the row in its order, each once.