diff --git a/u4/word_count.py b/u4/word_count.py new file mode 100644 index 0000000..ac196ca --- /dev/null +++ b/u4/word_count.py @@ -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)) \ No newline at end of file