Add u4/word_count.py

This commit is contained in:
Maksym Liashenko 2026-10-06 12:29:38 +00:00
parent ae3d68d172
commit ac9290f67a

9
u4/word_count.py Normal file
View File

@ -0,0 +1,9 @@
from collections import Counter
import re
def count_words(sentence):
pattern = r"[a-zA-ZáčďéíĺľňóôŕšťúýžÁČĎÉÍĹĽŇÓÔŔŠŤÚÝŽ0-9]+(?:'[a-zA-ZáčďéíĺľňóôŕšťúýžÁČĎÉÍĹĽŇÓÔŔŠŤÚÝŽ0-9]+)?"
clean_sentence = sentence.lower()
found_words = re.findall(pattern, clean_sentence)
return dict(Counter(found_words))