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} for k, v in d: print(k, v) | AOutput: a b | |
| 2d = {'x':1} d['x'] += 1 del d['x'] print(d['x']) | BError: Key deleted, KeyError | |
| 3for k, v in d.items(): print(k, v) | COutput: x 10 | |
| 4if 'name' in d: print(d['name']) | DValid: Unpack key and value | |
| 5d = {'a':1,'b':2} for k in d: print(k) | EOk: Check key before accessing | |
| 6d = {'x':10} for k,v in d.items(): print(k,v) | FError: Must use d.items() |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
for key in d: — Iterate through all keys in the dictionary.~~for v in d.values():for key in d:
print(key)for val in d.values():
print(val)for k, v in d.items():
print(k, v)if 'name' in d:
print('Found')for key in d:
print(d[key])