title: Appending to 2D lists in Python
body: <p>I've encountered what I think is a strange behavior in Python, and I'd like somebody to explain it if possible.</p>
  
  <p>I've created an empty 2D list</p>
  
  <pre><code>listy = [[]]*3
  
  print listy
  
  [[], [], []]
  </code></pre>
  
  <p>The following works as I'd expect:</p>
  
  <p><code>listy[1] = [1,2]</code> yields <code>[[], [1,2], []]</code></p>
  
  <p><code>listy[1].append(3)</code> yields <code>[[], [1,2,3], []]</code></p>
  
  <p>However, when I append to one of the empty lists, python appends to ALL of the sublists, as follows:</p>
  
  <p><code>listy[2].append(1)</code> yields <code>[[1], [1,2,3], [1]]</code>.</p>
  
  <p>Can anyone explain to me why this behavior occurs?</p>