import aoclib inp = aoclib.get_input(3, parser=aoclib.parse_lines_with_type_and_default( typ=lambda l: (l[: len(l)//2], l[len(l)//2:]), default=None)) def letter_value(x: str): if x.isupper(): return ord(x) - 38 else: return ord(x) - 96 def part1(): total = 0 for one, two in inp: both = set(one).intersection(set(two)) for thing in both: total += letter_value(thing) return total def part2(): a = inp a = [x + y for x, y in a] total = 0 for i in range(0, len(a), 3): common = set(a[i]).intersection(set(a[i+1])).intersection(set(a[i+2])) for thing in common: total += letter_value(thing) return total aoclib.main(part1, part2)