from functools import reduce from itertools import combinations def mult(iterable): return reduce(lambda x, y: x * y, iterable) def find_x_nums(data, sum_value, num): for vals in combinations(data, num): if sum(vals) == sum_value: return vals data = [int(str.strip(x)) for x in open("input")] print(mult(find_x_nums(data, 2020, 2))) print(mult(find_x_nums(data, 2020, 3)))