new
This commit is contained in:
parent
e9339d19bf
commit
97e8d650b7
@ -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
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user