lines = [] with open("6.input") as f: for line in f.readlines(): lines.append(line.strip()) yesanswers = set() yes_count = 0 for line in lines: if line == "": yes_count += len(yesanswers) yesanswers = set() else: yesanswers = yesanswers.union(set(line)) yes_count += len(yesanswers) print("Answer 1: {}".format(yes_count)) yes_count = 0 yesanswers = None for line in lines: if line == "": yes_count += len(yesanswers) yesanswers = None else: if yesanswers is None: yesanswers = set(line) else: yesanswers = yesanswers.intersection(set(line)) yes_count += len(yesanswers) print("Answer 2: {}".format(yes_count))