title: python how to change value of elements of sublists?
body: <p>I have the following code:</p>
  
  <pre><code>matrix = [[0] * 3] * 3
  matrix[0][0] = 2
  </code></pre>
  
  <p>I want to get the following result:</p>
  
  <pre><code>[[2, 0, 0], [0, 0, 0], [0, 0, 0]]
  </code></pre>
  
  <p>However it changes the first element of each sublist and returns this list:</p>
  
  <pre><code>[[2, 0, 0], [2, 0, 0], [2, 0, 0]]
  </code></pre>
  
  <p>If I define matrix as follow:</p>
  
  <pre><code>matrix = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
  </code></pre>
  
  <p>then it works.</p>
  
  <p>Could anyone tell me please, why it happens and how could solve this problem?</p>
  
  <p>Thanks</p>