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 :: append dataframe pandas 
Python :: leap year 
Python :: drop na dataframe 
Python :: def function python 
Python :: pygame tick time 
Python :: string count substring occurences pytohn 
Python :: python check if key exists 
Python :: plot multiple axes matplotlib 
Python :: numpy save multiple arrays 
Python :: newsapi in python 
Python :: pyspark rdd filter 
Python :: python replace double quotes with single quotes in string json loads 
Python :: append value to numpy array 
Python :: replace key of dictionary python 
Python :: python get attributes of object 
Python :: python multiple inheritance 
Python :: find factorial in python 
Python :: pandas df num rows 
Python :: print out a name in python 
Python :: seaborn histplot modify legend 
Python :: one line if statement no else 
Python :: matplotlib log scale y axis base 
Python :: Python capitalize first letter of string without changing the rest 
Python :: keras declare functional model 
Python :: python list of dictionaries to excel 
Python :: read json in python 
Python :: python if not null or empty 
Python :: catalan number 
Python :: Load dataset from seaborn 
Python :: python print green 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =