from pprint import pprint def search(l, key): for ix, x in enumerate(l): for iy, y in enumerate(l): for iz, z in enumerate(l): if x + y + z == key: return x, y, z 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, z = search(l, 2020) pprint((x, y, z)) print(x*y*z)