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 :: get adjacent cells in grid 
Python :: Consider using python 3 style super without arguments 
Python :: generate number of n bits python 
Python :: numpy replace 
Python :: plotly hide trace 
Python :: python writing to csv file 
Python :: debugar python 
Python :: change the color of the button on hovering tkinter 
Python :: how to multiply two tuples in python 
Python :: python iterate letters 
Python :: pyspark correlation 
Python :: spacy remove stop words 
Python :: pil image base64 
Python :: loop rought rows in pands 
Python :: run file as administrator python 
Python :: python order 2d array by secode element 
Python :: use python type hint for multiple return values 
Python :: how to set indian timezone in django 
Python :: how to delete records in pandas before a certain date 
Python :: python pil get pixel 
Python :: remove last element from dictionary python 
Python :: converting datetime object format to datetime format python 
Python :: cprofile usage python 
Python :: raise an APi error on django rest view 
Python :: python count distinct letters 
Python :: what is values_list in django orm 
Python :: how to define dtype of each column before actually reading csv file 
Python :: add a column while iterating rows pandas 
Python :: what is my python working directory 
Python :: python list all files in directory 
ADD CONTENT
Topic
Content
Source link
Name
8+1 =