zip the lists together, and sum the pairs
list(map(sum, zip(list1, list2)))
EDIT:
I did some basic testing, and the overwhelming winners were the list comprehension if the input data starts as lists, and numpy if you can have it as arrays before your operation
def test1(list1, list2):
l=[]
for x in range(0, len(list1)):
l.append(list1[x] + list2[x])
return l
def test2(list1, list2):
return list(map(sum, zip(list1, list2)))
def test3(list1, list2):
return [x+y for x, y in zip(list1, list2)]
import numpy as np
def test4(list1, list2):
return np.array(list1) + np.array(list2)
def test5(list1, list2):
return list1 + list2
from timeit import timeit
print(timeit('test1(list1, list2)', setup='list1 = list(range(100)); list2 = list(range(100))', globals=globals()))
print(timeit('test2(list1, list2)', setup='list1 = list(range(100)); list2 = list(range(100))', globals=globals()))
print(timeit('test3(list1, list2)', setup='list1 = list(range(100)); list2 = list(range(100))', globals=globals()))
print(timeit('test4(list1, list2)', setup='list1 = list(range(100)); list2 = list(range(100))', globals=globals()))
print(timeit('test4(list1, list2)', setup='list1 = np.array(list(range(100))); list2 = np.array(list(range(100)))', globals=globals()))
print(timeit('test5(list1, list2)', setup='list1 = np.array(list(range(100))); list2 = np.array(list(range(100)))', globals=globals()))
Gives me
15.42712744511664 # append
17.329718918073922 # my solution above
7.0252319818828255 # list comprehension
16.53089915495366 # numpy with list inputs
1.430903600063175 # numpy with array inputs that are double checked
0.6451617309357971 # numpy assuming array inputs
These are the times in seconds to execute the operation 1000000 times.
Numpy is surprisingly slow when forced to do np.array(list) every time.
Try it yourself at this repl.it