From bb461325fd4826f6dac3d995ab01b69e63279369 Mon Sep 17 00:00:00 2001 From: MartinSkovran Date: Mon, 5 Oct 2026 21:59:18 +0200 Subject: [PATCH] u4 --- u4/word_count.py | 17 +++++++++++++++++ 1 file changed, 17 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..276deda --- /dev/null +++ b/u4/word_count.py @@ -0,0 +1,17 @@ +from collections import defaultdict + +def count_words(sentance: str) -> dict: + words = defaultdict(0) + + delims = [":", "?", "!", "\n", "\t"] + + for delim in delims: + sentance = sentance.replace(delim, "") + + for w in sentance.split(" "): + words[w] += 1 + + return words + +print(count_words(""""To je heslo: 'HESLO 123'!", zvolala postava zo seriálu Panelák.\nPotom som utiekol.""")) + \ No newline at end of file