csci5451/assignments/02/process_output.py

24 lines
440 B
Python
Raw Normal View History

2023-10-30 09:09:03 +00:00
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()