title: Understand Python swapping: why is a, b = b, a not always equivalent to b, a = a, b?
body: <p>As we all know, the pythonic way to swap the values of two items <code>a</code> and <code>b</code> is</p>
  <pre><code>a, b = b, a
  </code></pre>
  <p>and it should be equivalent to</p>
  <pre><code>b, a = a, b
  </code></pre>
  <p>However, today when I was working on some code, I accidentally found that the following two swaps give different results:</p>
  <pre><code>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]
  
  nums = [1, 2, 4, 3]
  i = 2
  nums[nums[i]-1], nums[i] = nums[i], nums[nums[i]-1]
  print(nums)
  # [1, 2, 3, 4]
  </code></pre>
  <p>This is mind-boggling to me. Can someone explain to me what happened here? I thought in a Python swap the two assignments happen simultaneously and independently.</p>