title: Build a max heap and Iteration
body: <p>I have two questions:</p>
  
  <p><strong>1)</strong> Recently I'm try to build a <a href="http://en.wikipedia.org/wiki/Binary_heap" rel="nofollow">max heap</a>.  Even though I read <a href="http://en.wikipedia.org/wiki/Introduction_to_Algorithms" rel="nofollow">CLRS</a> I can't find the bug as I run it. The following is my code...</p>
  
  <pre><code>def maxHeapify(list, index):
      int = index
      left = (int+1) * 2 - 1
      right = (int+1) * 2
      largest = 0
      if left &lt; len(list):
          if (left &lt;= len(list)) &amp; (list[left] &gt;= list[int]):
              largest = left
          else: 
              largest = int
      if right &lt; len(list):
          if (right &lt;= len(list)) &amp; (list[right] &gt;= list[largest]):
              largest = right
      else:
          pass
      if largest != int:
          listNew = swapWithinList(list, int, largest)
          listNew = maxHeapify(listNew, largest)
      else:
          return listNew
  
  
  def swapWithinList(list, id1, id2):
      num1 = list[id1]
      num2 = list[id2]
      listNew = list[:id1]
      listNew.append(num2)
      listNew = listNew + list[(id1+1):id2]
      listNew.append(num1)
      listNew = listNew + list[(id2+1):]
      return listNew
  </code></pre>
  
  <p>I give input but the console just says:</p>
  
  <pre><code>UnboundLocalError: local variable 'listNew' referenced before assignment
  </code></pre>
  
  <p>does it mean that I put the return statement on the wrong line or there's something I haven't mentioned?</p>
  
  <p><strong>2)</strong> What is a iteration?</p>
  
  <p>I am a bit embarrassed when I ask the question. But what is a iteration? Wiki says each repetition of the process means it, so is it a result the loop gives each round?</p>
  
  <p>And iterator seems a basic element in Python, what's difference between iterator and iteration?</p>