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 arguments, and returns a list of two numbers from the list that add up to the target sum. If no such pair is found, it returns None.
Technology Stack : list, set
Code Type : Function
Code Difficulty : Intermediate
def sum_pairs(numbers, target_sum):
seen = set()
for number in numbers:
difference = target_sum - number
if difference in seen:
return [difference, number]
seen.add(number)
return None