Ich möchte eine tiefe Kopie von a dictin Python machen. Leider existiert die .deepcopy()Methode für die nicht dict. Wie mache ich das?
>>> my_dict = {'a': [1, 2, 3], 'b': [4, 5, 6]}
>>> my_copy = my_dict.deepcopy()
Traceback (most recent calll last):
File "<stdin>", line 1, in <module>
AttributeError: 'dict' object has no attribute 'deepcopy'
>>> my_copy = my_dict.copy()
>>> my_dict['a'][2] = 7
>>> my_copy['a'][2]
7
Die letzte Zeile sollte sein 3.
Ich möchte, dass Änderungen in my_dictden Schnappschuss nicht beeinflussen my_copy.
Wie mache ich das? Die Lösung sollte mit Python 3.x kompatibel sein.