""" Calculate the number of assignment pairs, where one range fully contains the other. """ contained = 0 with open("4.in") as fh: for line in fh: line = line.strip() elves = [] for elf in line.split(","): elf_s, elf_e = [int(x) for x in elf.split("-")] elves.append({ "start": elf_s, "end": elf_e }) elf0_contains_elf1 = ( elves[0]["start"] <= elves[1]["start"] and elves[0]["end"] >= elves[1]["end"] ) elf1_contains_elf0 = ( elves[1]["start"] <= elves[0]["start"] and elves[1]["end"] >= elves[0]["end"] ) if elf0_contains_elf1 or elf1_contains_elf0: contained += 1 print(contained)