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>

<p>using <a href="https://docs.python.org/3/library/itertools.html#itertools.accumulate" rel="nofollow"><code>itertools.accumulate</code></a></p>

<pre><code>&gt;&gt;&gt; import itertools
&gt;&gt;&gt; list(itertools.accumulate([1,1,3,3,4], lambda total,el: total+el))
[1, 2, 5, 8, 12]
</code></pre>

<p><em>disclaimer</em>: added in python 3.2</p>

python list