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 | |
|---|---|---|
| 1d = {'a': 1} d.get('b') print(d['b']) | AOk: Loop over key-value pairs | |
| 2d = {'x': 5} d.pop('y') | BError: Key 'y' not in dict | |
| 3d.get('missing', 0) | CValid: Returns 0 if key absent | |
| 4for k, v in d.items(): print(k, v) | DError: .get() doesn't add the key | |
| 5d = {'a':1,'b':2} print(list(d.keys())) | EOutput: 99 | |
| 6d = {'a':1} print(d.get('b', 99)) | FOutput: ['a', 'b'] |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
.keys() — Returns all keys in the dictionary.~~.values()d = {'a': 1, 'b': 2}
print(d.keys( ))d = {'a': 1, 'b': 2}
print(d.values( ))d = {'a': 1}
print(d.get('b', 0))d = {'x': 10}
val = d.pop('x')d = {'a': 1}
d.update({'b': 2})