def mid(values: list[str]): return values[len(values)//2] rules,updates = {}, [] with open('sample.data') as data: for line in data: if '|' in line: left, right = [int(i) for i in line.split('|')] if left in rules: rules[left].append(right) else: rules[left] = [right] if ',' in line: updates.append([int(i) for i in line.split(',')])