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]
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]
You can use
zip()
, which will "interleave" the two arrays together, and thenmap()
, which will apply a function to each element in an iterable:Here is another way to do it. We make use of the internal __add__ function of python:
Output
My answer is repeated with Thiru's that answered it in Mar 17 at 9:25.
It was simpler and quicker, here are his solutions:
You need numpy!
numpy array could do some operation like vectors