why cannot duplicate array using Python?
<p>Help! I have a big problem using Python. 
  We know in Python if <code>A=[1,2,3]</code> and if <code>B=A</code>, <code>B[1]=10</code>, then <code>A=[1,10,3]</code>.
  To fix this, we can <code>import copy</code> and <code>B =copy.copy(A)</code> or <code>B=A[:]</code>.
  In both cases, doing <code>B[1]=10</code> won't change <code>A</code>.</p>

<p>Now I extend <code>A</code> as a dictionary, and <code>A[1]=[1,2,3]</code>. Doing</p>

<pre><code>  A = {1:[1,2,3]}
  A[2] = A[1][:]
  for j in range(len(A[1])):
      A[2].append(4)
  print (A[2])
  print (A[1])
</code></pre>

<p>the result shows</p>

<pre><code>  [1, 2, 3, 4, 4, 4]
  [1, 2, 3]
</code></pre>

<p>It only changes <code>A[2]</code>, not <code>A[1]</code>. So it is good.
   But If I do <code>A[1] = [[1],[2],[3]]</code>, and</p>

<pre><code>  A = {1:[[1],[2],[3]]}
  A[2] = A[1][:]
  for j in range(len(A[1])):
      A[2][j].append(4)    
  print (A[2])
  print (A[1])
</code></pre>

<p>which instead gives me</p>

<pre><code>  [[1, 4], [2, 4], [3, 4]]
  [[1, 4], [2, 4], [3, 4]]
</code></pre>

<p>not</p>

<pre><code>  [[1, 4], [2, 4], [3, 4]]
  [[1], [2], [3]]
</code></pre>

<p>where <code>A[1]</code> was changed. Anyone can help me figure this out? I even use <code>A[2] = copy.copy(A[1])</code> still doesn't work. Thank you very much for the solution!!!!</p>