title: Python: fastest way to create a list of n lists
body: <p>So I was wondering how to best create a list of blank lists:</p>
  
  <pre><code>[[],[],[]...]
  </code></pre>
  
  <p>Because of how Python works with lists in memory, this doesn't work:</p>
  
  <pre><code>[[]]*n
  </code></pre>
  
  <p>This does create <code>[[],[],...]</code> but each element is the same list:</p>
  
  <pre><code>d = [[]]*n
  d[0].append(1)
  #[[1],[1],...]
  </code></pre>
  
  <p>Something like a list comprehension works:</p>
  
  <pre><code>d = [[] for x in xrange(0,n)]
  </code></pre>
  
  <p>But this uses the Python VM for looping. Is there any way to use an implied loop (taking advantage of it being written in C)?</p>
  
  <pre><code>d = []
  map(lambda n: d.append([]),xrange(0,10))
  </code></pre>
  
  <p>This is actually slower. :(</p>