How to add each item in a list to the previous one in Python?
<p>I have a list and I want to add each element in the list to the previous one. For example if I have the list <code>(1,1,3,3,4)</code>, I want the program to output <code>(1,2,5,8,12)</code>. </p>

<pre><code>[sum(a[:i]) for i in range(1,len(a)+1)]
</code></pre>

<p>is probably the easiest way ... I guess ...</p>

<pre><code>numpy.cumsum(a)
</code></pre>

<p>would also work i think</p>

python list