Beginner Python Tutorial 36 - How to Deep Copy a List (copy.deepcopy)

preview_player
Показать описание


~~~~~~~~~~~~~~~ CONNECT ~~~~~~~~~~~~~~~

~~~~~~~~~~~~~~ SUPPORT ME ~~~~~~~~~~~~~~

🅑 Bitcoin - 3HnF1SWTzo1dCU7RwFLhgk7SYiVfV37Pbq
🅔 Eth - 0x350139af84b60d075a3a0379716040b63f6D3853
Рекомендации по теме
Комментарии
Автор

Not only the video is explainin HOW to deep copy, it also explains the different clearly!

stepkurniawan
Автор

This was perfect for a problem I was having. Thank you!

mcskiletbiscuit
Автор

That's mean the value of first list is going to change just when we have nested list and we change a member of the nested list ?

firdausazad
Автор

why at 1:37 first element of my_favourite_things isn't changing while we are doing shallow copy

saisanthan
Автор

I have killed hours trying to understand, why is it changing my original list, you just explained it with 5 minutes, tnx alot

nahomelias
Автор

Dear Curry, Thank you so much for your effort but I have one question and if you find the time I would ask you to answer me regarding deep.copy ( ):
How can you explain that in the example below after deep.copy ( ) id from print(id(list_1[0][1]))
print(id(c_list_1[0][1])) are the same which means they are the same objects??
import copy
list_1 = [[1, 2], [3, 4]]
c_list_1 = copy.deepcopy(list_1)
print(list_1, c_list_1)
print(id(list_1[0][1]), 'id list_1[0][1]')
print(id(c_list_1[0][1]), 'id c_list_1[0][1]')


[[1, 2], [3, 4]] [[1, 2], [3, 4]]
1731516608 id list_1[0][1]
1731516608 id c_list_1[0][1]

Thanks in advance

mikijasar
Автор

.copy() isn't changing the original but deepcopy does right ?

firdausazad
Автор

This is great because I have a hard time literally building a foundation

TennesesseTitans
Автор

am still failing to out put anything.
fav_hobbies =["swimming", 7, ["gaming", ["athletics", "reading"]]]

copy = fav_hobbies.copy()
error
Traceback (most recent call last):
File "/root/Desktop/pythonprograms/hello.py", line 98, in <module>
copy = fav_hobbies.copy()
AttributeError: 'list' object has no attribute 'copy'

alhilton
Автор

Cmon bro I thought you add .thenewlist to the old list to copy😂😂
Example
Old = ["him", "her]
New = old.new()
Not knowing .copy was a function lol😂
Spent an hour figuring it out because of thr Example

OladapoAjayi-zd