avp26/u4/word_count.py
2026-10-06 12:27:09 +00:00

11 lines
184 B
Python

import re
from collections import Counter
def word_count(text):
pattern = r"\w+(?:'\w+)?"
words = re.findall(pattern, text.lower())
return dict(Counter(words))