list deep copy

40

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]]
import copy
 
list1 = ['A', 'B', 'C']
list2 = copy.deepcopy(list1)
 
print(list2)

Comments

Submit
0 Comments