Turn a programming chapter into cards

Make cards for the code you want to trace and the rules you want to remember. Then write a small program from a new requirement to see if you can apply the idea.

Predict what the code does

The chapter uses a Python list comprehension to keep readings of at least 10 pages. Put the inputs on the tracing card and check what happens at exactly 10.
Chapter example
Filter page counts in Python
pages = [8, 12, 5, 10]
print([
    p for p in pages if p >= 10
])
Trace the code, then recall the syntax
What does this Python expression return?
[p for p in [8, 12, 5, 10] if p >= 10]
[12, 10]
Where does the result expression go in a Python list comprehension?
Before the for clause.
The tracing card checks the boundary. The syntax card helps when you write a comprehension from scratch.

Pull out the rule you need to remember

Tracing the first card checks whether you can follow the code. The filter includes 10, and the values stay in input order. The second card checks whether you can recall a piece of syntax with the code out of sight. Use it if you pause over where to put an expression like p * 2 when writing a comprehension from memory. See list comprehensions in the Python tutorial.

To save either card in Repple, open your deck and choose Add → New card, then select Basic. Put the prompt in Front and the expected answer in Back, then choose Create Card. See how to write a self-contained question.

Write code for a new requirement

Close the chapter and write a Python function that takes a list of recipe serving counts. Keep only recipes that serve at most 4 people, then return the doubled serving count for each of those recipes, in input order.

Run your function with [6, 4, 2, 5] and check that it returns [8, 4]. Try [5, 6] too. That should return [].

Here you have to turn “at most 4” into a condition and decide what to put in the result list. If your code filters out everything that doubles to more than 4, check which value your condition tests. If you got stuck on where to put the doubling expression, review the syntax card.