This commit is contained in:
Oleksandr Mateshchuk 2026-10-06 12:27:09 +00:00
parent e6403d63c2
commit 30624828a4

View File

@ -1,15 +1,11 @@
import string import re
from collections import Counter
def word_count(text): def word_count(text):
words = [] pattern = r"\w+(?:'\w+)?"
for word in text.lower().split(): words = re.findall(pattern, text.lower())
cleaned_word = word.strip(string.punctuation)
if cleaned_word:
words.append(cleaned_word)
result = {} return dict(Counter(words))
for word in words:
result[word] = result.get(word,0) +1
return result