title: Initializing 2D array in Python
body: <p>I have a problem with initialzing a 2D array in python. I want a 6x6 array, I did</p>
  
  <pre><code>arr = [[None]*6]*6
  </code></pre>
  
  <p>But when I do: </p>
  
  <pre><code>&gt;&gt;&gt; arr[1][2]=10
  &gt;&gt;&gt; arr
  [[None, None, 10, None, None, None], [None, None, 10, None, None, None], [None, None, 10, None, None, None], [None, None, 10, None, None, None], [None, None, 10, None, None, None], [None, None, 10, None, None, None]]
  </code></pre>
  
  <p>Notice I just set 1 item, and its "replicated" on all rows. Whats wrong? I think it has to do with its referencing the same list, but how do I fix this? </p>
  
  <p>I figured </p>
  
  <pre><code>for key, _ in algos.items():
      algoData[key] = []
      for i in range(0,6):
          algoData[key].append([])
          for j in range(0,6):
              algoData[key][i].append(None)
  </code></pre>
  
  <p>works, but it seems long to just initialize an empty 6x6 array, what if I want a 10000x10000 array, it will be very inefficient?  </p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Can I also initialize a dictionary of 2D arrays? I have a dictionary like: </p>
  
  <pre><code>algos = { "FIFO": ..., "LRU": ..., "Random": ... }
  </code></pre>
  
  <p>I want to initialize a dictionary like below: </p>
  
  <pre><code>algoData = { "FIFO": 2D arr, "LRU": 2D arr, "Random": 2D arr }
  </code></pre>