arr=[-1,4,3,1]
k=1
arr[k],arr[arr[k]-1]=arr[arr[k]-1],arr[k]
print(arr)
gives unexpected and wrong output 4,1,3,1 whereas,
arr=[-1,4,3,1]
arr[1],arr[3]=arr[3],arr[1]
print(arr)
gives expected correct output -1,1,3,4
Can anyone justify why using a variable k in swapping is not leading to the correct output ?