title: Create a list with initial capacity in Python
body: <p>Code like this often happens:</p>
  <pre><code>l = []
  while foo:
      # baz
      l.append(bar)
      # qux
  </code></pre>
  <p>This is really slow if you're about to append thousands of elements to your list, as the list will have to be constantly resized to fit the new elements.</p>
  <p>In Java, you can create an ArrayList with an initial capacity. If you have some idea how big your list will be, this will be a lot more efficient.</p>
  <p>I understand that code like this can often be refactored into a list comprehension. If the <em>for</em>/<em>while</em> loop is very complicated, though, this is unfeasible. Is there an equivalent for us Python programmers?</p>