Python - Merge two lists with a simultaneous concatenation

concatenation, merge, python, python-3.x

Solution

This works:

>>> ListA = [1,2,3]
>>> ListB = [10,20,30]
>>> list(map(sum, zip(ListA, ListB)))
[11, 22, 33]
>>>

All of the built-ins used above are explained here.

Another solution would be to use a list comprehension.

Depending on your taste, you could do this:

>>> [sum(x) for x in zip(ListA, ListB)]
[11, 22, 33]
>>>

or this:

>>> [x+y for x,y in zip(ListA, ListB)]
[11, 22, 33]
>>>

Problem

``` ListA = [1,2,3] ListB = [10,20,30] ``` I want to add the contents of the lists together `(1+10,2+20,3+30)` creating the following list: ``` ListC = [11,22,33] ``` Is there a function that merges lists specifically in this manner?

Original source