python – How to add elements of two lists?



numbers([1,2,3], [3,4,5])    -> [4,6,8]


If you haven't "passed 'from' 'import'" yet, then the simplest option looks like this:

с=list(map(lambda x, y: x + y, a, b))

or like this:

c1 = [x+y for x,y in zip(a,b)] + (a if len(a) >= len(b) else b)[min(len(a), len(b)):]

If you need to wrap it in a function call, I hope you can do it yourself: on the input a and b, the specified expressions – as a parameter in return.

Scroll to Top