From 2bf60cfd3bcefd9d927a8a154179f79159d376f8 Mon Sep 17 00:00:00 2001 From: Oleksandr Mateshchuk Date: Tue, 6 Oct 2026 20:59:12 +0000 Subject: [PATCH] Aktualizovat u4/word_count.py --- u4/word_count.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/u4/word_count.py b/u4/word_count.py index addb945..55e6d4e 100644 --- a/u4/word_count.py +++ b/u4/word_count.py @@ -1,10 +1,13 @@ import re def count_words(text): - words = re.findall(r"\b[\w]+(?:'[\w]+)?\b", text.lower(), re.UNICODE) + words = re.findall(r"[^\W_]+(?:'[^\W_]+)?", text.lower(), re.UNICODE) result = {} for word in words: - result[word] = result.get(word, 0) + 1 + if word in result: + result[word] += 1 + else: + result[word] = 1 return result \ No newline at end of file