13/28
Part 3 of 6 · The whole pageLearn and do
A width for each row
The first follow-up in q-nfx-048 is a different n for each row. A real homepage has that: a row of big posters fits fewer titles across than a row of small tiles.
The clean way is to make the int case look like the list case, once, at the top:
print(widths_for(PAGE, 2))
print(widths_for(PAGE, [1, 0, 3]))
[2, 2, 2]
[1, 0, 3]
After that, zip(rows, widths) hands each row its own width, and nothing else changes. That's the sign of a good level 1: the follow-up is a two-line change, not a rewrite. The opposite design, an if on the type of width inside the row loop, works too, but it spreads one decision over the whole function, and the next follow-up has to find it.
PAGE with widths [1, 0, 3]. What does row 2, C, F, A, become?
Pick an answer above to see the rest