title: Why does a loop through a list of lists not recognise, that a list is a copy
body: <p>I encountered a (in my opinion) extremely strange behavior, when looping through a list of lists. It is very difficult to explain, but here is an example code:</p>
  
  <pre><code>k = [[0],[1],[2]]
  
  for lis in k:
      lis_copy = lis
      lis_copy.append(0)
      print lis
  </code></pre>
  
  <p>When executing this, I get: </p>
  
  <pre><code>[0, 0]
  [1, 0]
  [2, 0]
  </code></pre>
  
  <p>This is very strange for me, as the list which is appended is a copy of lis,
  but lis is appended as well. I would assume this list to be untouched.
  For example doing the same with a list of integers the following happens:</p>
  
  <pre><code>k = [0,1,2]
  
  for num in k:
      num_copy = num
      num_copy = 0
      print num
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>0
  1
  2
  </code></pre>
  
  <p>Just as expected num is not touched by the manipulation of num_copy.</p>
  
  <p>If somebody could explain why this is happening and how to avoid this, 
  like how to disconnect the lis_copy from is, that would be great.</p>
  
  <p>Wow, I am amazed I did not encounter mayor problems before, without knowing this. I think I should review quiet some of my code. Anyway I thought this is somehow connected to the loop, this seems not to be the case, therefore I think the best explanation can be found here: </p>
  
  <p><a href="https://stackoverflow.com/questions/2612802/how-to-clone-or-copy-a-list">How to clone or copy a list?</a></p>