news
This commit is contained in:
parent
4cb59c552a
commit
988f4e7438
@ -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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user