import sys import re pat = re.compile(r"\[(\d+)\] (.*)") outputs = {} for line in sys.stdin.readlines(): m = pat.match(line) if not m: # print(line) continue p = int(m.group(1)) rest = m.group(2) if p not in outputs: outputs[p] = [] outputs[p].append(rest) for p in sorted(outputs.keys()): lines = outputs[p] print(f"---- {p} ----") for line in lines: print(line) print()