Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python list deep copy

from copy import deepcopy
 
if __name__ == '__main__':
 
	x = [1, 2]
    y = [x, x]
 
	# create a copy of list y
    clone = deepcopy(y)
 
    # remove the last item from the original list
    x.pop()
 
    # cloned list remains unchanged
    print(clone)  # [[1, 2], [1, 2]]
Source by www.techiedelight.com #
 
PREVIOUS NEXT
Tagged: #python #list #deep #copy
ADD COMMENT
Topic
Name
5+8 =