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):
words = []
for word in text.lower().split():
cleaned_word = word.strip(string.punctuation)
if cleaned_word:
words.append(cleaned_word)
pattern = r"\w+(?:'\w+)?"
words = re.findall(pattern, text.lower())
result = {}
for word in words:
result[word] = result.get(word,0) +1
return result
return dict(Counter(words))