Benjamin Peterson added the comment:
Python doesn't have multiple assignment, just tuple unpacking. Consider the
order of evaluation here:
1. tmp = (6, x[2]) (i.e., (6, 2))
2. x[2] = tmp[0]
3. tmp2 = x.index(6) (= 2)
4. x[tmp2] = tmp[1] (i.e., x[2] = 2)
--
nosy: +benjamin.peterson
re
New submission from Nathan Brooks :
Faulty example:
x = [1,2,3,4,5,6,7]
# this should replace items 3 and 6 with each other
x[2], x[x.index(6)] = 6, x[2]
print(x)
[1,2,3,4,5,6,7]
Workaround:
x = [1,2,3,4,5,6,7]
i = x.index(6)
# this replaces items 3 and 6 in the list.
x[2], x[i] = 6, x[2]
print