1

I need to remove a item from a list and then add it again in the same position, like this:

x = ['a','b','c']
x2 = ['a','b','c']
x.remove(x[1])
...

x = x2 
x.remove(x[0])
...

#expected result:
x == ['b','c'] #True
x2 == ['a','b','c'] #True

#real result 

1. example == True
2. example == False 

That happens because when I use x = x2 I created an instance of x2 on x, but I just wanna assign x2 raw value to x. How can I do it?

Enzo Dtz
  • 309
  • 1
  • 12

1 Answers1

1

Replace this line:

x=x2

With:

x=x2.copy()

Or with:

x=x2[:]

For it to work.

U12-Forward
  • 65,118
  • 12
  • 70
  • 89