What is the output?
d = {}
d.setdefault('k', []).append(1)
d.setdefault('k', []).append(2)
print(d)
- {'k': [2]}
- {'k': [1, 2]}
- {'k': [1]}
- {'k': [[1], [2]]}
setdefault only inserts the default when the key is missing and always returns the stored list.
Play Problem Solving ▸