Skip to content

Instantly share code, notes, and snippets.

@twr14152
Created February 15, 2020 19:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save twr14152/1913cc3f76b37223dd4c310e8bcb86af to your computer and use it in GitHub Desktop.
Save twr14152/1913cc3f76b37223dd4c310e8bcb86af to your computer and use it in GitHub Desktop.
Using deepcopy with dictionary
In [64]: dict1 = copy.deepcopy(sample_dict)
In [65]: dict1
Out[65]: {'first': 1, 'second': 2, 'third': 3, 'a': 1, 'b': 2}
In [66]: sample_dict
Out[66]: {'first': 1, 'second': 2, 'third': 3, 'a': 1, 'b': 2}
In [68]: sample_dict.pop("first")
Out[68]: 1
In [69]: sample_dict
Out[69]: {'second': 2, 'third': 3, 'a': 1, 'b': 2}
In [70]: dict1
Out[70]: {'first': 1, 'second': 2, 'third': 3, 'a': 1, 'b': 2}
In [71]: id(sample_dict)
Out[71]: 3024432416
In [72]: id(dict1)
Out[72]: 3023654848
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment