title: Python swap elements
body: <p>I know there are at least these two methods:</p>
  
  <pre><code>array[i], array[j] = array[j], array[i]
  </code></pre>
  
  <p>And:</p>
  
  <pre><code>temp = array[i]
  array[i] = array[j]
  array[j] = temp
  </code></pre>
  
  <p>And in my testing of code that calls my swap function hundreds of thousands of times, the second approach is actually faster.</p>
  
  <p>The problem is, I'd like to know if there's an even faster way of doing it.</p>
  
  <p>I thought about allocating temp in the outer scope so that it doesn't have to be allocated every time swap is called, but that didn't help.</p>
  
  <p>Edit: I'm using this to implement a min heap with tens of thousands of elements in the heap.</p>
  
  <p>Also, I cannot use numpy. If arrays in python are like linked-lists, would simulating a true array using a dictionary with index numbers as keys be a better idea?</p>