Prashant Gaur Prashant Gaur - 1 year ago 86
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 Source

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

[x + y for x, y in zip(first, second)]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download