title: List comprehension for running total
body: <p>I want to get a running total from a list of numbers.</p>
  
  <p>For demo purposes, I start with a sequential list of numbers using <code>range</code></p>
  
  <pre><code>a = range(20)
  
  runningTotal = []
  for n in range(len(a)):
      new = runningTotal[n-1] + a[n] if n &gt; 0 else a[n]
      runningTotal.append(new)
  
  # This one is a syntax error
  # runningTotal = [a[n] for n in range(len(a)) if n == 0 else runningTotal[n-1] + a[n]]
  
  for i in zip(a, runningTotal):
      print "{0:&gt;3}{1:&gt;5}".format(*i)
  </code></pre>
  
  <p>yields</p>
  
  <pre><code>  0    0
    1    1
    2    3
    3    6
    4   10
    5   15
    6   21
    7   28
    8   36
    9   45
   10   55
   11   66
   12   78
   13   91
   14  105
   15  120
   16  136
   17  153
   18  171
   19  190
  </code></pre>
  
  <p>As you can see, I initialize an empty list <code>[]</code>, then <code>append()</code> in each loop iteration. Is there a more elegant way to this, like a list comprehension?</p>