#!/usr/bin/env python3 from functools import reduce import datetime import re, sys import math import numpy as np def tpl(l): me, rest = l.split() return me, rest def uni(l): return reduce(lambda a,b: a.union(b), l) def inter(l): return reduce(lambda a,b: a.intersection(b), l) def dprint(*args): sep = False for arg in args: if sep: print('--------') sep = True for a, b in arg.items(): print('%10s: %s' % (a, ','.join(b))) print() fn = sys.argv[1] if len(sys.argv) > 1 else 'input%s' % datetime.datetime.now().day with open(fn) as f: lines = [l.strip() for l in f.readlines()] t = [tpl(l) for l in lines] pgphs = f.read().split('\n\n') header, footer = f.read().split('\n\n') rules = {a: b for a, b in (mkrule(l) for l in header.strip().split('\n'))} things = [mkthing(l) for l in footer.strip().split('\n')]