Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python copy

org_list = [1, 2, 3, 4, 5, 6, 7, 8, 9]
new_list = org_list.copy()

# For lists in lists you need deepcopy()

import copy

org_list = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
new_list = copy.deepcopy(org_list)
 
Comment

copy python

import copy

l = [0, 1, [2, 3]]
l_assign = l                   # assignment
l_copy = l.copy()              # shallow copy
l_deepcopy = copy.deepcopy(l)  # deep copy

l[1] = 100
l[2][0] = 200
print(l)
# [0, 100, [200, 3]]

print(l_assign)
# [0, 100, [200, 3]]

print(l_copy)
# [0, 1, [200, 3]]

print(l_deepcopy)
# [0, 1, [2, 3]]
Comment

PREVIOUS NEXT
Code Example
Python :: binary search in python 
Python :: python while loop 
Python :: Example of break, continue and pass statements in python 
Python :: python increment by 1 
Python :: how to find the last occurrence of a character in a string in python 
Python :: import gpio raspberry pi 
Python :: pandas get size of each group 
Python :: python interview questions and answers pdf 
Python :: python print not working 
Python :: NumPy invert Syntax 
Python :: python floor float 
Python :: Accessing elements from a Python Dictionary using the get method 
Python :: selecting a specific value and corrersponding value in df python 
Python :: python floor function 
Python :: python how to vectorize a function 
Python :: percentage plot of categorical variable in python woth hue 
Python :: list dataframe to numpy array 
Python :: drop pandas 
Python :: xml to python list in python 
Python :: create new spreadsheet 
Python :: python string: .upper() 
Python :: f string 
Python :: service 
Python :: add to list in python 
Python :: solving linear equation using numpy 
Python :: python use cases 
Python :: python string 
Python :: drop variable pandas 
Python :: multiple values in a dictionary python 
Python :: pandas group by to dataframe 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =