I'm struggling with this strange behaviour in Python (2 and 3):
>>> a = [1, 2]
>>> a[a.index(1)], a[a.index(2)] = 2, 1
This results in:
>>> a
[1, 2]
But if you write
>>> a = [1, 2]
>>> a[a.index(1)], a[a.index(2)] = x, y
where x, y != 2, 1 (can be 1, 1, 2, 2 , 3, 5, etc.), this results in:
>>> a == [x, y]
True
As one would expect. Why doesn't a[a.index(1)], a[a.index(2)] = 2, 1 produce the result a == [2, 1]?
>>> a == [2, 1]
False