Tiefe Kopie eines Diktats in PythonPython

Python-Programme
Guest
 Tiefe Kopie eines Diktats in Python

Post by Guest »

Ich möchte eine tiefe Kopie eines Diktats in Python erstellen. Leider existiert die .deepcopy () -Methode für das DICT nicht. Wie mache ich das? < /P>

>>> my_dict = {'a': [1, 2, 3], 'b': [4, 5, 6]}
>>> my_copy = my_dict.deepcopy()
Traceback (most recent calll last):
File "", line 1, in
AttributeError: 'dict' object has no attribute 'deepcopy'
>>> my_copy = my_dict.copy()
>>> my_dict['a'][2] = 7
>>> my_copy['a'][2]
7
< /code>

Die letzte Zeile sollte 3 < /code>. Code> Beeinflussen Sie nicht den Snapshot my_copy < /code>. < /p>

Wie mache ich das? Die Lösung sollte mit Python 3.x.

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post