Few very minor readability tricks * replacing the typical "if x not in list: list[x] = ..." pattern with defaultdict * replace string.split('\n') with splitlines()