from string import ascii_letters as lett value = {} score = 0 x = 0 for i in range(len(lett)): value[lett[i]] = i+1 f = open('input3.txt', 'r') inp = f.read().splitlines(keepends=False) while x < len(inp): fir = inp[x] sec = inp[x+1] thi = inp[x+2] for i in range(len(fir)): if fir[i] in sec and fir[i] in thi: charr = fir[i] break score = score + value[charr] x = x + 3 print(score)