avp26/u4/word_count.py

10 lines
273 B
Python

import re
from collections import Counter
def count_words(text: str) -> dict[str, int]:
text = text.lower()
words = re.findall(r"[a-z0-9áäčďéíľňóôŕšťúýž]+(?:'[a-z0-9áäčďéíľňóôŕšťúýž]+)?", text)
return dict(Counter(words))