From 9847f3cf6e13de9d562b8ef3d0d78c4c30a4b45d Mon Sep 17 00:00:00 2001 From: MartinSkovran Date: Mon, 5 Oct 2026 22:43:45 +0200 Subject: [PATCH] u4_repair_2_3 --- u4/word_count.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/u4/word_count.py b/u4/word_count.py index 539f89d..a6f0894 100644 --- a/u4/word_count.py +++ b/u4/word_count.py @@ -4,7 +4,9 @@ def count_words(sentance: str) -> dict: sent_list = list(sentance) words = defaultdict(int) - delims = [":", "?", "!", "\n", "\t", ",", "."] + SPECIAL_CHAR = oct(7) + + delims = [":", "?", "!", "\n", "\t", ",", ".", "_"] del_chars = ['"'] forbidden = delims + del_chars + [" ", "'", ""] @@ -16,13 +18,15 @@ def count_words(sentance: str) -> dict: sent_list[i] = "" if(ch == "'"): if((sent_list[max(i-1, 0)] not in forbidden) and (sent_list[min(i+1, len(sent_list)-1)] not in forbidden)): - sent_list[i] = '^' + sent_list[i] = SPECIAL_CHAR else: sent_list[i] = "" for w in ''.join(sent_list).lower().split(" "): if w == "": continue - words[w.replace("^", "'")] += 1 + words[w.replace(SPECIAL_CHAR, "'")] += 1 - return dict(words) \ No newline at end of file + return dict(words) + +print(count_words("""seriál: seriálik ako Dunaj: Panelák!!&@$%^&""")) \ No newline at end of file