news
This commit is contained in:
parent
4cb59c552a
commit
988f4e7438
@ -1,17 +1,18 @@
|
||||
import string
|
||||
def count_words(sentence: str) -> dict[str, int]:
|
||||
sentence = sentence.lower()
|
||||
|
||||
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
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user