Understand Python swapping: why is a, b = b, a not always equivalent to b, a = a, b?
As we all know, the pythonic way to swap the values of two items a and b is a, b = b, a and it should be equivalent to b, a = a, b However, today when I was working on some code, I accidentally found that the following two swaps give different results: nums = [1, 2, 4, 3] i = 2 nums[i], nums[nums[i]-1] = nums[nums[i]-1], nums[i] print(nums) # [1, 2, 4, 3] nu