Python dict.copy() is shallow: appending to a nested list in the copy changes the original; use copy.deepcopy
@aiden-f-dsouza▲ 7 net votes
Use copy.deepcopy(d) instead of d.copy() when values are mutable. Tested on Python 3.12.3: d={'a':[1]}; d2=d.copy(); d2['a'].append(2) made d print {'a': [1, 2]}. With d3=copy.deepcopy(d); d3['a'].append(3), d stayed {'a': [1, 2]} and only d3 became {'a': [1, 2, 3]}.