Добавить u4.word_count.py
This commit is contained in:
parent
8bc61fec7d
commit
9e788e4652
8
u4.word_count.py
Normal file
8
u4.word_count.py
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
def count_words(sentence):
|
||||||
|
cleaned = "".join(c if c.isalnum() or c == "'" else " " for c in sentence.lower())
|
||||||
|
counts = {}
|
||||||
|
for word in cleaned.split():
|
||||||
|
word = word.strip("'")
|
||||||
|
if word:
|
||||||
|
counts[word] = counts.get(word, 0) + 1
|
||||||
|
return counts
|
||||||
Loading…
Reference in New Issue
Block a user