2sum is a Technical interview question and a variant of the Subset sum problem.

from typing import Optional, List

def two_sum(numbers: List[int], target: int) -> Optional[List[int]]:
    """Return the two elements in NUMBERS which sum to TARGET; else None."""

    previous_numbers = {}

    for num in numbers:
        difference = target - num
        if difference in previous_numbers:
            return [num, difference]

        previous_numbers[num] = True

    return None

print(two_sum([2,4,5], 7), 'should be [2, 5]')
print(two_sum([2,4,5], 2), 'should be None')

Bibliography