Count parenthesis parity in a room

This commit is contained in:
Joscha 2025-07-07 00:57:10 +02:00
parent a4ac55036f
commit a2e29d58d0

24
count_parentheses.py Normal file
View file

@ -0,0 +1,24 @@
import json
from argparse import ArgumentParser
from pathlib import Path
from typing import Counter
def main():
parser = ArgumentParser()
parser.add_argument("path", type=Path)
args = parser.parse_args()
chars = Counter[str]()
with open(args.path) as f:
print("Reading lines")
for line in f:
content = json.loads(line)["content"]
chars += Counter(content)
for c in "()[]{}<>":
print(f"{c} - {chars[c]:6}")
if __name__ == "__main__":
main()