From ac9290f67a60fbae54a629ef982001d53d8ced42 Mon Sep 17 00:00:00 2001 From: Maksym Liashenko Date: Tue, 6 Oct 2026 12:29:38 +0000 Subject: [PATCH] Add u4/word_count.py --- u4/word_count.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 u4/word_count.py 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