Python array weird behavior
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/10191749/strange-behavior-of-lists-in-python">Strange behavior of lists in python</a>  </p>
</blockquote>



<p>I am attempting to initialize a 6 by 6 2D array of None. Here is what I do:</p>

<pre><code>arr = [[None]*6]*6
</code></pre>

<p>Then I attempt to insert some values as follows:</p>

<pre><code>arr[2][0] = arr[2][1] = 0
</code></pre>

<p>Which instead of changing the values of (2,0) and (2,1) to 0 and keeping the rest of the array full of None, it changes all the columns 0 and 1 to 0. </p>

<p>Full example:</p>

<pre><code>&gt;&gt;&gt; arr = [[None]*6]*6
&gt;&gt;&gt; arr
[[None, None, None, None, None, None], [None, None, None, None, None, None], [None, None, None, None, None, None], [None, None, None, None, None, None], [None, None, None, None, None, None], [None, None, None, None, None, None]]

&gt;&gt;&gt; arr[2][0] = arr[2][1] = 0
&gt;&gt;&gt; arr
[[0, 0, None, None, None, None], [0, 0, None, None, None, None], [0, 0, None, None, None, None], [0, 0, None, None, None, None], [0, 0, None, None, None, None], [0, 0, None, None, None, None]]
</code></pre>

<p>Why does this happen and how can I prevent it?</p>

<p>p.s. my use of the phrase 'weird behavior' implies weird to me, not python messing up :)</p>
