title: Changing iterable variable during loop
body: <p>Let <code>it</code> be an iterable element in python.
  In what cases is a change of <code>it</code> inside a loop over <code>it</code> reflected? Or more straightforward: When does something like this work?</p>
  
  <pre><code>it = range(6)
  for i in it:
      it.remove(i+1)
      print i
  </code></pre>
  
  <p>Leads to 0,2,4 being printed (showing the loop runs 3 times).</p>
  
  <p>On the other hand does </p>
  
  <pre><code>it = range(6)
  for i in it:
      it = it[:-2]
      print it
  </code></pre>
  
  <p>lead to the output:</p>
  
  <pre><code>[0,1,2,3]
  [0,1]
  []
  []
  []
  [],
  </code></pre>
  
  <p>showing the loop runs 6 times. I guess it has something to do with in-place operations or variable scope but cannot wrap my head around it 100% sure.</p>
  
  <p><strong>Clearification:</strong> </p>
  
  <p>One example, that doesn't work:</p>
  
  <pre><code>it = range(6)
  for i in it:
      it = it.remove(i+1)
      print it
  </code></pre>
  
  <p>leads to 'None' being printed and an Error (NoneType has no attribute 'remove') to be thrown.</p>