import aoclib inp = aoclib.get_input(4, parser=aoclib.parse_lines_with_func(lambda line: line.split(","))) def to_range(substring): start, end = [int(x) for x in substring.split("-")] return list(range(start, end+1)) def part1(): count = 0 for line in inp: one, two = [set(to_range(x)) for x in line] if one.issubset(two) or two.issubset(one): count += 1 return count def part2(): count = 0 for line in inp: one, two = [set(to_range(x)) for x in line] one = set(one) if one.intersection(two): count += 1 return count aoclib.main(part1, part2)