title: How does "vec = [[0] * 9] * 9" work in Python?
body: <p>I was trying to initialize a matrix in Python. I did this:</p>
  <pre><code>matrix = [[0] * 9] * 9
  matrix[0][0] = 1
  print(matrix[1][0])
  </code></pre>
  <p>This outputs <strong>1</strong>.</p>
  <p>Can someone explain why this happens and how <strong>[[0] * 9] * 9</strong> works.</p>
  <p>My guess is that all the vectors are pointers to the same vector instead of to different vectors, but I don't know why that happens and why <strong>[0] * 9</strong> doesn't have the same issue.</p>