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 | |
|---|---|---|
| 1d1 + d2 | AValid: Dictionary comprehension | |
| 2{k for k, v in d} | BOk: Merge two dicts using unpacking | |
| 3{k: v for k, v in d.items()} | CError: This is a set, not a dict comprehension | |
| 4{**d1, **d2} | DOutput: {'a': 1, 'b': 2} | |
| 5{x: x**2 for x in range(4)} | EError: Use d1 | d2 or {**d1, **d2} to merge | |
| 6dict(zip(['a','b'], [1,2])) | FOutput: {0: 0, 1: 1, 2: 4, 3: 9} |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
Dict comprehension — {key: value for item in iterable} builds a dictionary concisely.~~Merge operatorsquares = {x: x**2 for x in range(5)}result = dict(zip(names, scores))pos = {k: v for k, v in d.items() if v > 0}merged = {**d1, **d2}inverted = {v: k for k, v in d.items()}