From 988f4e743860c1b7e5e7dfe91630630b71afa71f Mon Sep 17 00:00:00 2001 From: va270fv Date: Tue, 6 Oct 2026 11:49:09 +0000 Subject: [PATCH] news --- u4/word_count.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/u4/word_count.py b/u4/word_count.py index 6d236bb..92a5b84 100644 --- a/u4/word_count.py +++ b/u4/word_count.py @@ -1,17 +1,18 @@ -def count_words(sentence : str) -> dict[str, int] : +import string +def count_words(sentence: str) -> dict[str, int]: + sentence = sentence.lower() - for char in sentence: - if not char.isanum() and char not in ("'"," "): + if not char.isanum() and char not in ("'", " "): sentence = sentence.replace(char, " ") + words = sentence.split() result = {} for word in words: cleaned_word = word.strip("'") - if cleaned_word: + if cleaned_word: result[cleaned_word] = result.get(cleaned_word, 0) + 1 + return result - - \ No newline at end of file