You can download this code by clicking the button below.
This code is now available for download.
This function takes a list of numbers and a target value, and returns a tuple of two numbers from the list that add up to the target value. If no such pair exists, it returns None.
Technology Stack : List (list), Dictionary (dict)
Code Type : Function
Code Difficulty : Intermediate
def sum_pairs(numbers, target):
seen = {}
for number in numbers:
complement = target - number
if complement in seen:
return (complement, number)
seen[number] = True
return None