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 sum, then returns a pair of numbers that add up to the target sum. If no such pair is found, it returns None.
Technology Stack : List (list), Dictionary (dict)
Code Type : Algorithm
Code Difficulty : Intermediate
def sum_pairs(numbers, target_sum):
seen = {}
for number in numbers:
if target_sum - number in seen:
return (target_sum - number, number)
seen[number] = True
return None