title: How is sum() used to merge lists
body: <p>I am learning trees in python, which I was showed with these functions to build a tree:</p>
  
  <pre><code>def tree(label, branches=[]):
      return [label] + list(branches)
  
  def label(tree):
      return tree[0]
  
  def branches(tree):
      return tree[1:]
  </code></pre>
  
  <p>There is a function that can extract all the nodes of a tree into a list:</p>
  
  <pre><code>def all_nodes(tree):
      return [label(tree)] + sum([all_nodes(b) for b in branches(tree)], [])
  
  T = tree(1, [tree(2, [tree(4), tree(5)]), tree(3, [tree(6), tree(7)])])
  print(all_nodes(T))
  # &gt;&gt;&gt; [1, 2, 4, 5, 3, 6, 7]
  </code></pre>
  
  <p>You can see that this worked very well, but I got confused how <code>sum()</code> is used here.</p>
  
  <p>I know that a list can be added to another list:</p>
  
  <pre><code>print([1] + [2]) # &gt;&gt;&gt; [1, 2]
  </code></pre>
  
  <p>But I can't make it work by using <code>sum()</code>:</p>
  
  <pre><code>a, b = [1], [2]
  print(sum(a, b))
  # &gt;&gt;&gt; TypeError: can only concatenate list (not "int") to list
  print(sum([a, b]))
  # &gt;&gt;&gt; TypeError: unsupported operand type(s) for +: 'int' and 'list
  </code></pre>
  
  <p>In the <code>tree</code> function, how did <code>sum()</code> work to merge all the lists?</p>