From 6dad46914b9d91de442e681848dd065576572044 Mon Sep 17 00:00:00 2001 From: MartinSkovran Date: Tue, 6 Oct 2026 12:44:50 +0200 Subject: [PATCH] u4_optim --- .gitignore | 1 + u4/word_count.py | 8 +++----- 2 files changed, 4 insertions(+), 5 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..68b819a --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.test.py \ No newline at end of file diff --git a/u4/word_count.py b/u4/word_count.py index a7905ab..bb887a6 100644 --- a/u4/word_count.py +++ b/u4/word_count.py @@ -6,10 +6,10 @@ def count_words(sentance: str) -> dict: SPECIAL_CHAR = oct(7) - delims = [":", "?", "!", "\n", "\t", ",", ".", "_", '&', '@', '$', '%', '^', '&'] - del_chars = ['"'] + delims = ":?!\n\t,._&@$^&*()%" + del_chars = '"' - forbidden = delims + del_chars + [" ", "'", ""] + forbidden = list(delims) + list(del_chars) + [" ", "'", ""] for i, ch in enumerate(sent_list): if(ch in delims): @@ -28,5 +28,3 @@ def count_words(sentance: str) -> dict: words[w.replace(SPECIAL_CHAR, "'")] += 1 return dict(words) - -print(count_words("""seriál: seriálik ako Dunaj: Panelák!!&@$%^&""")) \ No newline at end of file