Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
Shade in the A or B circle for each question.
Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 1[x * 2 for x in nums] | ABuilds a new list with every number in nums doubled | |
| 2[x for x in nums if x > 10] | BBuilds a new list with only the numbers in nums greater than 10 | |
| 3A list comprehension copies every item from a loop into a new list in one expression | CRound brackets make a generator, not a list. Square brackets are needed to build a list. | |
| 4A list comprehension can transform each item, for example by making each name uppercase | Dupper = [n.upper() for n in names] | |
| 5evens = [x for x in nums where x % 2 == 0] | Ecopy = [x for x in items] | |
| 6doubled = (x * 2 for x in nums) | F'where' is not Python. A condition in a list comprehension uses the keyword 'if'. |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
[x for x in items] — A list comprehension builds a new list from a loop in one expression. Add 'if condition' to filter items, or change x (e.g. x * 2) to transform each item.doubled = [x * 2 for x in nums]evens = [n for n in nums if n % 2 == 0]squares = [n * n for n in range(1, 6)]marks = [55, 82, 47, 90]
passes = [m for m in marks if m >= 50]names = ["ava", "liam"]
big = [n.upper() for n in names]