Why the first one gives the wrong swap like this? Thanks a lot.
a = [-1,4,3,1]
a[3], a[a[3]-1] = a[a[3]-1], a[3]
print a #gives [-1, 4, 1, -1], which is wrong
a = [-1,4,3,1]
a[a[3]-1], a[3] = a[3], a[a[3]-1]
print a #gives [1, 4, 3, -1]
Why the first one gives the wrong swap like this? Thanks a lot.
a = [-1,4,3,1]
a[3], a[a[3]-1] = a[a[3]-1], a[3]
print a #gives [-1, 4, 1, -1], which is wrong
a = [-1,4,3,1]
a[a[3]-1], a[3] = a[3], a[a[3]-1]
print a #gives [1, 4, 3, -1]