I ran into a weird behavior trying to swap elements of an array.
Initial State
i = 1
nums = [0, 1]
What didn't worked
nums[i], nums[nums[i]-1] = nums[nums[i]-1], nums[i]
print(nums) # [0, 1]
What worked
nums[nums[i]-1], nums[i] = nums[i], nums[nums[i]-1]
print(nums) # [1, 0]
I believed both expressions should have had the same outcome as the right-side of assignment is evaluated first.
Tested on Python 2.7.16 and Python 3.7.6 on macOS Catalina, 10.15.4.
Note: nums[1], nums[0] = nums[0], nums[1]
and nums[0], nums[1] = nums[1], nums[0]
work just as expected.