avp26/u4/word_count.py
2026-10-06 20:57:16 +00:00

10 lines
213 B
Python

import re
def count_words(text):
words = re.findall(r"\b[\w]+(?:'[\w]+)?\b", text.lower(), re.UNICODE)
result = {}
for word in words:
result[word] = result.get(word, 0) + 1
return result