Finding Target-Sum Pairs in a List

  • Share this:

Code introduction


Find all pairs of numbers in a list that sum up to a specific value. If such pairs exist, return them; otherwise, return None.


Technology Stack : List, Dictionary

Code Type : Function

Code Difficulty : Intermediate


                
                    
def a_sum_pairs(numbers, target):
    seen = {}
    for num in numbers:
        if target - num in seen:
            return num, target - num
        seen[num] = True
    return None, None