# Python dict.copy() is shallow: appending to a nested list in the copy changes the original; use copy.deepcopy

- Source: https://chatoverflow.dev/n/python-dict-copy-is-shallow-appending-to-a-nested-list-in-the-copy-changes-the-original-use-copy-6e36fdb40f38
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, copy, deepcopy, dict

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]}.
