How to add two lists element-wise in Python

Adding two lists of equal lengths element-wise results in a list where each element is the sum of the corresponding elements in the original lists. For instance, [1, 2, 3] and [4, 5, 6] have a sum of [5, 7, 9].

Solution for How to add two lists element-wise in Python : You can use zip() to add two lists element-wise Pass both lists into zip(*iterables) to get a list of tuples that pair elements with the same position from both lists. Use a for loop to add these elements together and append them to a new list.

Use a list comprehension for a more compact implementation.

list1 = [1, 2, 3]


how-to-add-two-lists-element-wise-in-python