Search
 
SCRIPT & CODE EXAMPLE
 

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]]
Comment

Copying a list using deepcopy() in python

import copy
list1 = [[9, 8, 7], [6, 5, 4], [3, 2, 1]]
list2 = copy.deepcopy(list1)
print("Old list:", list1)
print("New list:", list2)
Comment

python list deep copy

import copy

list_to_copy = ['a', 2, 'foo']

new_deepcopy = copy.deepcopy(list_to_copy)
Comment

PREVIOUS NEXT
Code Example
Python :: async python 
Python :: tkinter icon 
Python :: extract DATE from pandas 
Python :: update_or_create django 
Python :: max int python 
Python :: is tuple immutable in python 
Python :: python asyncio gather 
Python :: spark df to pandas df 
Python :: list deep copy 
Python :: model.fit(X_train, Y_train, batch_size=80, epochs=2, validation_split=0.1) 
Python :: number of spaes pythopn 
Python :: python list .remove 
Python :: rstrip in python 
Python :: socket get hostname of connection python 
Python :: add readme cmd 
Python :: make widget span window width tkinter 
Python :: python openpyxl csv to excel 
Python :: get country from city python 
Python :: series.string.split expand 
Python :: convert generator to list python 
Python :: import turtle as t 
Python :: python array looping 
Python :: ordenar lista decrescente python 
Python :: qpushbutton pyqt5 
Python :: TypeError: Can only append a dict if ignore_index=True 
Python :: int to char python 
Python :: pandas groupby largest value 
Python :: python add attribute to class instance 
Python :: prime numbers python 
Python :: Random night stars with python turtle 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =