title: Why do I need to supply an empty list to merge lists with sum()?
body: <p>I have several lists, stored in a list, itself created in a loop of unknown number of iterations, and I need to concatenate them all. Example:</p>
  
  <pre><code>lists = [range(i) for i in range(1,5)]
  lists
  Out[1]: [[0], [0, 1], [0, 1, 2], [0, 1, 2, 3]]
  </code></pre>
  
  <p>So, now I want to turn them into a single, flat list. I can do this by just adding them:</p>
  
  <pre><code>biglist = lists[0] + lists[1] + lists[2] + lists[3]
  </code></pre>
  
  <p>...but that gets boring very quickly. I could write a <code>for</code> loop which iterates over the inner lists:</p>
  
  <pre><code>biglist = []
  for smallist in lists:
      biglist += smallist
  biglist
  Out[2]: [0, 0, 1, 0, 1, 2, 0, 1, 2, 3] 
  </code></pre>
  
  <p>This works but requires three lines of code and handling intermediate results, so it cannot work inline and gets in the way of preferring functional code.</p>
  
  <p>But since all I need is to add some lists to each other, and there's already a builtin function for that in Python, it stands to reason I could just use <code>sum(lists)</code> -- however:</p>
  
  <pre><code>sum(lists)
  Traceback (most recent call last):
    File "D:\program_files\Anaconda\envs\SPINE_dev\lib\site-packages\IPython\core\interactiveshell.py", line 2878, in run_code
      exec(code_obj, self.user_global_ns, self.user_ns)
    File "&lt;ipython-input-12-827ffc5ab7d2&gt;", line 1, in &lt;module&gt;
      sum(lists)
  TypeError: unsupported operand type(s) for +: 'int' and 'list'
  </code></pre>
  
  <p>What's the issue? Should this not work?
  I went looking for an answer and only found <a href="https://coderwall.com/p/tszoiq/python-sum-convert-list-of-lists-to-a-list" rel="nofollow noreferrer">this trick</a>, which works, but without explanation:</p>
  
  <pre><code>sum(lists, [])
  Out[3]: [0, 0, 1, 0, 1, 2, 0, 1, 2, 3]
  </code></pre>
  
  <p>Note that the original hint was to use <code>list(sum(lists, []))</code>, but it seems to work just fine without using <code>list()</code>, which looks much better, too.</p>
  
  <p>So, the question: Why do I need to supply an empty list? Secondary question: Why would someone recommend wrapping that statement in a type conversion, and are there scenarios (or Python versions) where that would be necessary?</p>
  
  <p>I'm using Python 2.7.10</p>