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