title: Element (array) "multiplication" vs. list comprehension initialization
body: <p>In relation to the question: </p>
  
  <p><a href="https://stackoverflow.com/questions/2397141/how-to-initialize-a-two-dimensional-array-in-python">How to initialize a two-dimensional array in Python?</a></p>
  
  <p>While working with a two dimentional array, I found that initializing it in a certain way would produce unexpected results. I would like to understand the difference between initializing an 8x8 grid in these two ways:</p>
  
  <pre><code>&gt;&gt;&gt; a =  [[1]*8]*8
  &gt;&gt;&gt; a
  [[1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1], \
   [1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1], \
   [1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1], \
   [1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1]]
  </code></pre>
  
  <p>vs. </p>
  
  <pre><code>&gt;&gt;&gt; A =  [[1 for i in range(8)] for j in range(8)]
  &gt;&gt;&gt; A
  [[1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1], \
   [1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1], \
   [1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1], \
   [1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1]]
  </code></pre>
  
  <p>The unexpected results were that any element accessed with the indeces [0-6][x] would point to the last row in [7][x]. The arrays <em>look</em> identical in the interpreter, hence my confusion. What is wrong with the first approach? </p>
  
  <p>If relevant, these arrays hold references to GTK EventBoxes that represent the squares of a chess board. After changing the initialization approach to the list-comprehension method, the squares respond properly to the intended hover and click events. </p>