Predict what the code does
pages = [8, 12, 5, 10]
print([
p for p in pages if p >= 10
])[p for p in [8, 12, 5, 10] if p >= 10][12, 10]for clause.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.