+ 1
How to create a duplicate list of another list that is not synced?
I saw that a=[3,4,2] , b=a and if a[1]=7 then b[1] also become 7.
2 Answers
+ 1
When you do b = a on a mutable object (i.e. list, set, dict, etc.), you create a REFERENCE to the object a.
You then just need to do b = a.copy(), b = a[:] or use the copy module
0
a = [1,2,3]
b = a
c = list(a)
a[0] = 'changed'
print(a[0])
print(b[0])
print(c[0])