csci5451/assignments/02/process_output.py
2023-10-30 09:35:04 +00:00

26 lines
No EOL
456 B
Python

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()
print("Done.")