You can download this code by clicking the button below.
This code is now available for download.
This function accepts a list of numbers and a target sum, and returns a list of two numbers whose sum equals the target sum. If no such pair exists, it returns None.
Technology Stack : set collection
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