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

[x + y for x, y in zip(first, second)]

If you have a list of lists (instead of just two lists):

lists_of_lists = [[1, 2, 3], [4, 5, 6]]
[sum(x) for x in zip(*lists_of_lists)]
# -> [5, 7, 9]
Answer from tom on Stack Overflow
๐ŸŒ
The Renegade Coder
therenegadecoder.com โ€บ code โ€บ how-to-sum-elements-of-two-lists-in-python
How to Sum Elements of Two Lists in Python: Comprehensions and More โ€“ The Renegade Coder
May 27, 2024 - In short, one of the best ways to sum elements of two lists in Python is to use a list comprehension in conjunction with the addition operator.
Discussions

How to sum the elements of 2 lists in python? - Stack Overflow
Copylist1 = [1, 2, 3, 4, 5] list2 ... list2) sum = [x + y for (x, y) in zipped_lists] ... Save this answer. ... Show activity on this post. ... Copylist1 = [1,2,3,4,5] list2 = [10,11,12,13,14] result = [list1[i]+list2[i] for i in range(len(list1))] print(result) ... Find the answer to your question by asking. Ask question ... See similar questions with these tags. ... For a given function, how do I create an association with values that are functions for the first two derivatives ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
python - Two sum with two lists - Code Review Stack Exchange
Suppose we have two sorted lists, and we want to find one element from the first, and the other element from the 2nd list, where the sum of the two elements equal to a given target. If there are mu... More on codereview.stackexchange.com
๐ŸŒ codereview.stackexchange.com
January 23, 2017
python - Modify a code to sum two lists (element-wise) - Stack Overflow
I want to sum two lists (element-wise). More on stackoverflow.com
๐ŸŒ stackoverflow.com
Fastest way to sum two lists of items with each other in python - Stack Overflow
I have a bit of a strange request that I'm looking to solve with utmost efficiency; I have two lists list_1 and list_2, which are both the same length and will both only ever contain integers greater More on stackoverflow.com
๐ŸŒ stackoverflow.com
June 29, 2017
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ adding together two lists?
r/learnpython on Reddit: Adding together two lists?
November 1, 2022 -

Hi, I'm trying to create a function which adds together items from two lists and I can't figure out what I'm doing wrong. My initial code was very similar to this but did not work, after googling other people's solutions I've essentially copy and pasted what multiple people on various forums advised, but still have not had any success. Currently it just prints out a blank list, "[ ]", and I don't know why. Can anyone help?

def list_sum(a, b):
    a = []
    b = []
    c = []
    for i in range(len(a)):
        listAdd = (a[i] + b[i])
        c.append(listAdd)
    return(c)
    
if __name__ == "__main__":
    a = [1, 2, 3]
    b = [4, 5, 6]
    add = list_sum(a, b)
    print(add)
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-adding-two-list-elements
Add Elements of Two Lists in Python - GeeksforGeeks
July 11, 2025 - # Input lists a = [1, 3, 4, 6, 8] b = [4, 5, 6, 2, 10] # Add corresponding elements using list comprehension c = [a[i] + b[i] for i in range(len(a))] # Print the result print(c) Output ยท [5, 8, 10, 8, 18] Table of Content ยท Using zip() Function ยท ...
๐ŸŒ
DEV Community
dev.to โ€บ therenegadecoder โ€บ how-to-sum-elements-of-two-lists-in-python-17c7
Python Sum of List : How to Sum Elements of Two Lists in Python - DEV Community
September 5, 2019 - While it does a great job summing integers in an iterable, it crashes when trying to merge two sublists with the following error: Traceback (most recent call last): File "<pyshell#3>", line 1, in <module> all_devices = [sum(pair) for pair in zip(ethernet_devices, usb_devices)] File "<pyshell#3>", line 1, in <listcomp> all_devices = [sum(pair) for pair in zip(ethernet_devices, usb_devices)] TypeError: unsupported operand type(s) for +: 'int' and 'list'
๐ŸŒ
YouTube
youtube.com โ€บ watch
[23] How to Sum Elements of Two Lists in Python | Python for Beginners - YouTube
In this tutorial, we will discuss how to sum elements of two lists in python, or you can say how to merge to list in python.I will recommend, one of the best...
Published: September 23, 2020
Find elsewhere
๐ŸŒ
Spark By {Examples}
sparkbyexamples.com โ€บ home โ€บ python โ€บ python add two lists by index wise
Python Add Two Lists By Index Wise - Spark By {Examples}
May 31, 2024 - How to add two lists in python, for example, index-wise summation of numbers? You can perform index-wise addition or summation of two lists by using list
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ adding-two-python-lists-elements
Adding two Python lists elements
list1 = [7, 5.7, 21, 18, 8/3] list2 = [9, 15, 6.2, 1/3, 11] result = [sum(pair) for pair in zip(list1, list2)] print(result)
๐ŸŒ
TechBeamers
techbeamers.com โ€บ python-add-two-list-elements
How to Add Elements of Two Lists - TechBeamers
November 30, 2025 - In this method, Python for loop is used to iterate the smaller of the two lists. In every iteration, add the corresponding values at the running index from the two lists, and insert the sum in a new list.
๐ŸŒ
w3resource
w3resource.com โ€บ python-exercises โ€บ list โ€บ python-data-type-list-exercise-194.php
Python: Sum two or more lists, the lengths of the lists may be different - w3resource
June 28, 2025 - # 2. Use 'zip(*map(...))' to ensure ... sublists with zeros. result = [sum(x) for x in zip(*map(lambda x: x + [0] * max(map(len, test_list)) if len(x) < max(map(len, test_list)) else x, test_list))] return result # Return the ...
Top answer
1 of 4
4

Assuming that your lists are sorted and this is something that comes out of problem description and the part where you need to find something in 99% of that kind of questions you want to use binary search. So basically all your code could be written like this:

from bisect import bisect_left


def binary_search(a, x):
    pos = bisect_left(a, x)
    return pos if pos != len(a) and a[pos] == x else -1


def two_sum(a, b, target):
    result = []
    for num in a:
        index = binary_search(b, target-num)
        if index != -1:
            result.append((num, b[index]))
    return result

Now if you want to save some memory, you might want to make two_sum a generator, which will make it look like this:

def two_sum(a, b, target):
    result = []
    for num in a:
        index = binary_search(b, target-num)
        if index != -1:
            yield num, b[index]

I cannot really call my answer a review to your code because I completely overwrote a solution for this. But as I mentioned in the beginning whenever a problem says something about sorted lists and searching on it, most likely you will use bsearch in your solution.

2 of 4
3

I re-constructed your algorithm using generators, which I find easier on the eyes (instead of indexing) for these sort of list traversals. Other than that, the code is the same.

def two_sum(list1, list2, target):
    # Get a generator for each list
    l1 = iter(list1)
    l2 = reversed(list2)

    # loop and append to results list
    result = []
    try:
        # get the first sample from each list
        x = next(l1)
        y = next(l2)
        while True:

            # If we find a match, record it
            if x + y == target:
                new_pair = x, y
                result.append(new_pair)

                # get next unique elements
                x = next(l1)
                while x == new_pair[0]:
                    x = l1.next()

                y = next(l2)
                while y == new_pair[1]:
                    y = next(l2)

            # if no match, then get new element from one list
            elif x + y > target:
                y = next(l2)
            else:
                x = next(l1)

    # when one of the generators runs out of elements it will assert
    except StopIteration:
        pass
    return result


print(two_sum([1, 3, 5, 7], [2, 3, 3, 5], 6))
๐ŸŒ
Sololearn
sololearn.com โ€บ en โ€บ Discuss โ€บ 3198656 โ€บ how-do-i-sum-elements-2-by-2-list-python
how do I sum elements 2 by 2 list? (python)
March 14, 2023 - sl_scroll_/de/Discuss/2689918/i-made-a-bmi-calculator-in-python-and-youa-are-supposed-to-write-the-height-in-meter-i-want-whenever-you-write-the-height-in-cePending
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python-ways-to-sum-list-of-lists-and-return-sum-list
Python - Ways to sum list of lists and return sum list - GeeksforGeeks
December 18, 2024 - A result list sum_list is initialized with zeros. A nested loop iterates through each list and its elements, adding corresponding values. ... The task of concatenate two lists of lists row-wise, meaning we merge corresponding sublists into a single sublist.
๐ŸŒ
Javatpoint
javatpoint.com โ€บ how-to-add-two-lists-in-python
How to add two lists in Python - Javatpoint
How to add two lists in Python with python, tutorial, tkinter, button, overview, entry, checkbutton, canvas, frame, environment set-up, first python program, operators, etc.
๐ŸŒ
HCL GUVI
studytonight.com โ€บ python-howtos โ€บ elementwise-addition-of-two-lists-in-python
HCL GUVI | Learn to code in your native language
HCL GUVI's Data Science Program was just fantastic. It covered statistics, machine learning, data visualization, and Python within its curriculum.