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 as input, and returns a list containing a pair of numbers whose sum equals the target sum. If no such pair is found, it returns None.
Technology Stack : Built-in data types (list, dictionary)
Code Type : Function
Code Difficulty : Intermediate
def sum_pairs(numbers, target_sum):
seen = {}
for number in numbers:
complement = target_sum - number
if complement in seen:
return [seen[complement], number]
seen[number] = number
return None