Collections and control flow express policy
Control flow is where a program's policy becomes visible. A for loop says what is repeated, if says which cases differ, and match can name a finite set of shapes when that improves clarity. Lists preserve order, sets express membership, and dictionaries connect keys to values. Choosing a set for a list of allowed codes communicates that duplicates and order do not matter. Choosing a dictionary for rows keyed by an identifier communicates lookup intent.
Choosing a set for allowed codes tells the next reader that duplicates and order do not matter. Choosing a dictionary keyed by identifier tells them lookup is the intent. Every collection choice is a sentence about the policy, written where a comment would go stale.
Write the simplest loop that makes the decision inspectable. A comprehension is useful when it maps or filters without side effects. It becomes a liability when it contains nested conditions, I/O, or mutations. Check boundaries explicitly: empty input, one item, duplicate keys, and a value just outside a threshold.
Truthiness is convenient and sometimes ambiguous. An empty list, 0, and None are all false, but they mean different things in a business rule. If zero is a valid quantity, write quantity is None when testing absence. Use enumerate for positions, zip for parallel sequences, and collections.Counter when frequency is the actual question.
Micro-lab in the app
Predict, run, change or break, explain: change the threshold in this loop and account for every printed branch.
for score in [42, 68, 71, 39]:
print('pass' if score >= 60 else 'review')A reconciliation must preserve the order of the source rows and flag duplicate identifiers. Which design communicates both requirements?
A threshold treats zero as valid but missing as an error. Which condition is precise?
Notes are kept with your account, alongside your progress and your gate claims. The lesson itself is readable without one.