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