0
a = [10, 12, 14]
b = a
b.remove(12) 
print(a)
print(b)

Result is:

[10, 14]
[10, 14]

The result is same when I use pop, del function

It is also same when I delete from a (a.remove, a.pop, del a)

What I want is (like disconnection):

[10, 12, 14]
[10, 14]

It seems like remove function deletes the element in the original list too

1 Answers1

0

What you want is to reference a copy of a with b, not the same list, so just copy it:

from copy import copy
a = [10, 12, 14]
b = copy(a)
b.remove(12) 
print(a)
print(b)

[10, 12, 14]
[10, 14]

Here you have the live example

Netwave
  • 40,134
  • 6
  • 50
  • 93