How to find sum of list of lists using for-loop
<pre><code>prefer_indic = [[[0, 4, 6, 5, 45, 1], [2, 3, 5, 6, 7, 1]],[[0, 0.27, 6, 7, 32, 3], [0.01, 0.39, 0, 0, 0, 0]]]
</code></pre>

<p>I want to create a sum list that will add every value from every list of lists with each corresponding ones.
To be accurate i want: </p>

<p><code>sum = [[0+0, 4+0.27, 6+6, 5+7, 45+32, 1+3], [2+0.1, 3+0.39, 5+0, 6+0, 7+0, 1+0]]</code></p>

<p>I want to do it with a for loop so that i can use the same algorithm for bigger list of lists.I made the example simple to make it more readable. I have python 2.7 .</p>

<p>I would define a function that adds two lists, then use a list comprehension to compute your desired result:</p>

<pre><code>def add_lists(a, b):
    return list(x+y for x, y in zip(a, b))

s = list(add_lists(*l) for l in zip(*prefer_indic))
</code></pre>

<p>For you example</p>

<pre><code>prefer_indic = [[[0, 4, 6, 5, 45, 1], [2, 3, 5, 6, 7, 1]],[[0, 0.27, 6, 7, 32, 3], [0.01, 0.39, 0, 0, 0, 0]]]
</code></pre>

<p>the result will be</p>

<pre><code>[[0, 4.27, 12, 12, 77, 4], [2.01, 3.39, 5, 6, 7, 1]]
</code></pre>

python python-2.7 for-loop sum