Which fix removes the bug?
import copy
a = {'x': [1, 2]}
b = copy.copy(a)
b['x'].append(3)
print(len(a['x']))
- Use
copy.deepcopy(a)for the copy - Use
copy.clone(a)for the copy - Change
b['x']tob.get('x')here - Append with
b['x'] = b['x'] + [3]
A shallow copy shares the inner list, so appending is visible through
Play Problem Solving ▸
a.