From a357fd6df56bb6fbe36a8cfce57a459ab7137d47 Mon Sep 17 00:00:00 2001 From: Oleksandr Mateshchuk Date: Tue, 6 Oct 2026 20:50:59 +0000 Subject: [PATCH] Aktualizovat u4/word_count.py --- u4/word_count.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/u4/word_count.py b/u4/word_count.py index d67cd90..3d9b93f 100644 --- a/u4/word_count.py +++ b/u4/word_count.py @@ -1,13 +1,14 @@ import re -from collections import Counter +text = input() +words = re.findall(r"[^\W_]+(?:'[^\W_]+)?", text.lower(), re.UNICODE) +counts = {} -def count_words(text): - text = text.replace("_", " ") - text = text.replace("’", "'") - pattern = r"[^\W_]+(?:'[^\W_]+)?" - words = re.findall(pattern, text.lower()) - return dict(Counter(words)) +for word in words: + if word in counts: + counts[word] += 1 + else: + counts[word] = 1 - -word_count = count_words \ No newline at end of file +for word, count in sorted(counts.items()): + print(f"{word}: {count}") \ No newline at end of file