Добавить u4.word_count.py

This commit is contained in:
Arina Dohadailo 2026-10-06 12:08:19 +00:00
parent 8bc61fec7d
commit 9e788e4652

8
u4.word_count.py Normal file
View 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