From d9fa93a26cc8fae3aa44b1075ef97c5d495442d6 Mon Sep 17 00:00:00 2001 From: Patrik Tulach Date: Tue, 6 Oct 2026 13:36:52 +0200 Subject: [PATCH] u4 --- u4/word_count.py | 19 +++++++++++++++++++ 1 file changed, 19 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..2e6771e --- /dev/null +++ b/u4/word_count.py @@ -0,0 +1,19 @@ +def count_words(sentence): + dict = {} + separators = [".", ",", ":", "!", "?", "\n", "\t", "'", " "] + + previous_i = 0 + for i, chr in enumerate(sentence): + if chr in separators: + word = sentence[previous_i:i] + previous_i = i + 1 + word = word.lower().strip(" ") + if word in separators or word == "": + continue + if word in dict: + print(dict) + dict[word] = dict[word] + 1 + print(dict) + else: + dict.update({word : 1}) + return dict \ No newline at end of file