An example of how to sum elements from multiple lists of same size in python:
Let's define for example 3 lists of same size in python:
a = [1,2,3,4]
b = [10,20,30,40]
c = [1,1,1,1]
To create a new list by adding the element by adding elements from multiple lists, a solution is to use a list comprehension and zip:
d = [x+y+z for x, y, z in zip(a, b, c)]
[12, 23, 34, 45]
Note: to add all elements together just use sum():
tot = sum(d)
Hi, I am Ben.
I have developed this web site from scratch with Django to share with everyone my notes. If you have any ideas or suggestions to improve the site, let me know ! (you can contact me using the form in the welcome page). Thanks!