Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python deepcopy

>>> import copy
>>> nums = [1, 2, 3]
>>> data = {'a': 10, 'b': nums}
>>> data
{'a': 10, 'b': [1, 2, 3]}
>>> data_copy = copy.copy(data)
>>> data_deep = copy.deepcopy(data)
>>> data_copy
{'a': 10, 'b': [1, 2, 3]}
>>> data_deep
{'a': 10, 'b': [1, 2, 3]}
>>> data_copy['a'] += 2
>>> nums[1:1] = [254]
>>> data
{'a': 10, 'b': [1, 254, 2, 3]}
>>> data_copy
{'a': 12, 'b': [1, 254, 2, 3]}
>>> data_deep
{'a': 10, 'b': [1, 2, 3]}
Comment

deepcopy python

copy() method creates a new reference variable to the original data whereas deepcopy dont reflect the change after modification of the original data
Comment

PREVIOUS NEXT
Code Example
Python :: typer python 
Python :: Range all columns of df such that the minimum value in each column is 0 and max is 1. in pandas 
Python :: python sweep two numbers 
Python :: lru cache 
Python :: append numeric number in and auto increment in using pandas 
Python :: change group box border color pyqt5 
Python :: multithreaded programming in python 
Python :: python select from list by boolean list 
Python :: combination in python 
Python :: how to remove whitespace from string in python 
Python :: how can I print all items in a tuple, separated by commas? 
Python :: loading bar python 
Python :: NumPy bitwise_xor Syntax 
Python :: bar chart in python 
Python :: unpacking tuples in python 
Python :: pandas flip x and y axis 
Python :: google scikit learn decision tree 
Python :: How split() works in Python? 
Python :: Python - Comment lire une ligne de fichier par ligne 
Python :: python json nan 
Python :: 20 minute timer with python 
Python :: toolbar pyqt 
Python :: pandas.core.indexes into list 
Python :: defaultdict in python 
Python :: tkinter asksaveasfile 
Python :: python filter list with list of booleans 
Python :: python replace text 
Python :: import csv 
Python :: first step creating python project 
Python :: Amazon price tracker in Python 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =