fi = open("in.txt", "r") sum = 0 ip = fi.readlines() # part 1 for line in ip: half = line[0:len(line)//2] ohalf = line[len(line)//2::] common = set() _ = [ common.add(el) for el in half if el in ohalf ] el: str = common.pop() if el.isupper(): sum += ord(el) - 38 else: sum += ord(el) - 96 print(sum) # part 2 sum2 = 0 for i in range(0, len(ip)-2, 3): common = set() _ = [ common.add(el) for el in ip[i].strip() if (el in ip[i+1].strip() and el in ip[i+2].strip()) ] el: str = common.pop() if el.isupper(): sum2 += ord(el) - 38 else: sum2 += ord(el) - 96 print(sum2)