This commit is contained in:
Vadym Afanasiev 2026-10-06 11:49:09 +00:00
parent 4cb59c552a
commit 988f4e7438

View File

@ -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() sentence = sentence.lower()
for char in sentence: for char in sentence:
if not char.isanum() and char not in ("'"," "): if not char.isanum() and char not in ("'", " "):
sentence = sentence.replace(char, " ") sentence = sentence.replace(char, " ")
words = sentence.split() words = sentence.split()
result = {} result = {}
for word in words: for word in words:
cleaned_word = word.strip("'") cleaned_word = word.strip("'")
if cleaned_word: if cleaned_word:
result[cleaned_word] = result.get(cleaned_word, 0) + 1 result[cleaned_word] = result.get(cleaned_word, 0) + 1
return result return result