Answers for "python deep copy list"

4

python clone object

import copy

new_ob = copy.deepcopy(old_ob)
Posted by: Guest on December-29-2020
5

example of a deep copy in python

# deep copy example in python
import copy

old_list = [[1, 1, 1], [2, 2, 2], [3, 3, 3]]
new_list = copy.deepcopy(old_list)

old_list[1][0] = 'BB'

print("Old list:", old_list)
print("New list:", new_list)

# OUTPUT
Old list: [[1, 1, 1], ['BB', 2, 2], [3, 3, 3]]
New list: [[1, 1, 1], [2, 2, 2], [3, 3, 3]]
Posted by: Guest on September-20-2020
3

.copy python

new_list = list.copy()

# returns a new list without modifying the orginal list.
Posted by: Guest on January-31-2021
-2

python deep copy list

new_list = [i for i in old_list]
Posted by: Guest on February-27-2021

Python Answers by Framework

Browse Popular Code Answers by Language