Count parenthesis parity in a room
This commit is contained in:
parent
a4ac55036f
commit
a2e29d58d0
1 changed files with 24 additions and 0 deletions
24
count_parentheses.py
Normal file
24
count_parentheses.py
Normal 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()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue