ahand = ("A", "B", "C") bhand = ("X", "Y", "Z") win_tbl = ( ("A", "Y"), ("B", "Z"), ("C", "X"), ) def load(filename): with open(filename) as f: t = 0 for l in f: a, b = l.rstrip().split(" ") h = bhand.index(b) + 1 ai = ahand.index(a) bi = bhand.index(b) if ai == bi: t += h + 3 elif (a, b) in win_tbl: t += h + 6 else: t += h return t assert load("demo.txt") == 15 t = load("data.txt") print(f"You have {t} points.")