From c96717455cef38fa2af00b9c6eec40d5c0438799 Mon Sep 17 00:00:00 2001 From: Joscha Date: Thu, 23 Oct 2025 01:44:36 +0200 Subject: [PATCH] Count smileys as well --- count_parentheses.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/count_parentheses.py b/count_parentheses.py index 54cac13..7dc6524 100644 --- a/count_parentheses.py +++ b/count_parentheses.py @@ -3,21 +3,28 @@ from argparse import ArgumentParser from pathlib import Path from typing import Counter +PARENS = list("()[]{}<>") +SMILEYS = [":D", "D:"] + def main(): parser = ArgumentParser() parser.add_argument("path", type=Path) args = parser.parse_args() - chars = Counter[str]() + count = Counter[str]() with open(args.path) as f: print("Reading lines") for line in f: - content = json.loads(line)["content"] - chars += Counter(content) + content: str = json.loads(line)["content"] + count += Counter(content) + for smiley in SMILEYS: + count[smiley] += content.count(smiley) - for c in "()[]{}<>": - print(f"{c} - {chars[c]:6}") + for paren in PARENS: + print(f" {paren} - {count[paren]:6}") + for smiley in SMILEYS: + print(f"{smiley} - {count[smiley]:6}") if __name__ == "__main__":