title: Python - Dynamic Nested List
body: <p>So I'm trying to generate a nested list in Python based on a width and a height. This is what I have so far:</p>
  
  <pre><code>    width = 4
      height = 5
      row = [None]*width
      map = [row]*height
  </code></pre>
  
  <p>Now, this obviously isn't quite right. When printed it looks fine:</p>
  
  <pre><code>[[None, None, None, None],
   [None, None, None, None],
   [None, None, None, None],
   [None, None, None, None],
   [None, None, None, None]]
  </code></pre>
  
  <p>But attempting to assign a value to a position like so:</p>
  
  <pre><code>map[2][3] = 'foo'
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code>[[None, None, None, 'foo'],
   [None, None, None, 'foo'],
   [None, None, None, 'foo'],
   [None, None, None, 'foo'],
   [None, None, None, 'foo']]
  </code></pre>
  
  <p>Clearly this happens because each sublist is really just referencing the same object, row, so changing one, changes them all. So this is closest I've got!</p>
  
  <p>How can I dynamically generate a nested list? Thanks!</p>