<jupyter_start><jupyter_text>Daily 1 This problem was recently asked by Google.Given a list of numbers and a number `k`, return whether any two numbers from the list add up to `k`.For example, given `[10, 15, 3, 7]` and `k` of `17`, return `true` since `10 + 7 = 17`.Bonus: Can you do this in one pass?<jupyter_code>def k_sum(l, k):
    for i in l:
        for j in l:
            if i + j == k:
                return True
    return False
l = [10, 15, 3, 7]
k = 17

k_sum(l, k)
d = {}
d[-1] = 0

def k_sum_2(l, k):
    d = {}
    for i in l:
        rest = k - i
        if d.get(i):
            return True
        d[rest] = True
    return False
l = [10, 15, 3, 7]
k = 25

k_sum_2(l, k)<jupyter_output><empty_output><jupyter_text>Solution<jupyter_code>def two_sum(lst, k):
    """O(N^2)"""
    for i in range(len(lst)):
        for j in range(len(lst)):
            if i != j and lst[i] + lst[j] == k:
                return True
    return False

def two_sum(lst, k):
    """O(N); lookups in set is O(1)"""
    seen = set()
    for num in lst:
        if k - num in seen:
            return True
        seen.add(num)
    return False
l = [10, 15, 3, 7]
k = 25

two_sum(l, k)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13884297520661157, 'fraction_numerical': 0.03636363636363636, 'mean_word_length': 2.1373056994818653, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '470726', 'license': 'MIT', 'n_tokens_mistral': 508, 'n_tokens_neox': 467, 'n_words': 166, 'path': 'daily/daily-1.ipynb', 'repo_name': 'joekickass/python-misc', 'size': '1210'}