title: python - assignment to a slice avoids errors with modifying list being iterated
body: <p>I read <a href="https://stackoverflow.com/q/3346696/3130953">here</a> and have learned through bad code that there are problems iterating over lists and changing the list elements within the loop. They suggest one method is to create a copy of the list as such:</p>
  
  <pre><code>for x in a[:]: # make a slice copy of the entire list
      if len(x) &gt; 6: a.insert(0, x)
  </code></pre>
  
  <p>Does referring to a slice of a list create a temporary copy created for execution of the loop? </p>
  
  <p>What about in the following case found <a href="https://stackoverflow.com/q/1207406/3130953">here</a>:</p>
  
  <pre><code>somelist[:] = [x for x in somelist if not determine(x)]
  </code></pre>
  
  <p>In this case instead of assigning the solution to a new list, they assign output to a slice of the input list. What is the order of operations here which allows this to be done? Why do we not run into the same errors mentioned when modifying list elements through usual for loops? </p>