0

I have a question about the variables id() in python:

a=[2,3]
b=a
print b
>>>[2, 3]

a.remove(2)
print b
>>>[3]

This is because id(a) == id(b)?; how can I avoid this? I need to define b in another way?

Nicolás Medina
  • 59
  • 2
  • 11

1 Answers1

0

You can slice it, so you get a copy of the first list:

b= a[:]
farhawa
  • 10,120
  • 16
  • 49
  • 91