from pprint import pprint def search(l, key): for ix, x in enumerate(l): for iy, y in enumerate(l): if x == y: continue if x + y == key: return x, y with open("sum.txt", "r", encoding="utf-8") as f: s = f.read() ls = s.split() l = [int(x) for x in ls] x, y = search(l, 2020) pprint((x, y)) print(x*y)