Prashant Gaur Prashant Gaur - 2 months ago 22
Python Question

Add SUM of values of two LISTS into new LIST

I have the following two lists:

first = [1,2,3,4,5]
second = [6,7,8,9,10]


Now I want to add items of both lists into a new list.

output should be

three = [7,9,11,13,15]

tom tom
Answer

The zip function is useful here, used with a list comprehension.

[x + y for x, y in zip(first, second)]