title: Python: Why these two same list of list created through different means behaving differently?
body: <p>Below two snippets create list of list of dimension(5x5) but they producing different result</p>
  
  <ul>
  <li><code>a = [[0]*5]*5</code></li>
  <li><code>b = [[0 for x in range(5)] for y in range(5)]</code></li>
  </ul>
  
  <p>Both will given me same list:</p>
  
  <pre><code>&gt;&gt;&gt;a
  [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]
  &gt;&gt;&gt;b
  [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]
  </code></pre>
  
  <p>But when I do following both give different result:</p>
  
  <pre><code>a[0][0] = 1
  [[1, 0, 0, 0, 0], [1, 0, 0, 0, 0], [1, 0, 0, 0, 0], [1, 0, 0, 0, 0], [1, 0, 0, 0, 0]]
  b[0][0] = 1
  [[1, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]
  </code></pre>
  
  <p>Why so ?</p>