From 97e8d650b7b3a4b24a01b9ba0231bfb446e0dc9d Mon Sep 17 00:00:00 2001 From: va270fv Date: Tue, 6 Oct 2026 11:35:51 +0000 Subject: [PATCH] new --- u4/word-count.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/u4/word-count.py b/u4/word-count.py index 547c4a3..6d236bb 100644 --- a/u4/word-count.py +++ b/u4/word-count.py @@ -1,3 +1,17 @@ -def count_words(sentence): +def count_words(sentence : str) -> dict[str, int] : + sentence = sentence.lower() + + + for char in sentence: + 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: + result[cleaned_word] = result.get(cleaned_word, 0) + 1 + return result + \ No newline at end of file