self.x
and self.y
both reference the same list object in memory. Meaning, when you update one, the other will reflect the change.
You can see this behavior in the below demonstration:
>>> a = [1, 2, 3]
>>> b = a
>>>
>>> # The contents of a and b are the same
>>> a
[1, 2, 3]
>>> b
[1, 2, 3]
>>>
>>> # And their ids are the same
>>> id(a)
33908856
>>> id(b)
33908856
>>>
>>> a.append(4)
>>> a
[1, 2, 3, 4]
>>> b
[1, 2, 3, 4]
>>>
If you want to change this behavior, you could assign self.y
to a shallow copy of self.x
:
self.y = self.x[:]
See a demonstration below:
>>> a = [1,2,3]
>>> b = a[:]
>>>
>>> # The contents of a and b are the same
>>> a
[1, 2, 3]
>>> b
[1, 2, 3]
>>>
>>> # But their ids are different
>>> id(a)
33984680
>>> id(b)
33984960
>>>
>>> a.append(4)
>>> a
[1, 2, 3, 4]
>>> b
[1, 2, 3]
>>>