From 07e462be1958b68ae5a4bc8ff87548f75c35ca98 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 6 Oct 2026 13:47:46 +0200 Subject: [PATCH] u4 --- u4/word_count.py | 20 ++++++++++++++++++++ 1 file changed, 20 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..5fc92dc --- /dev/null +++ b/u4/word_count.py @@ -0,0 +1,20 @@ +def count_word(sentence): + words = [] + word = "" + + for character in sentence: + if character.isalnum() or character == " ": + word += character.lower() + else: + if word.strip("'"): + words.append(words.strip("'")) + word = "" + if word.strip("'"): + words.append(word.strip("'")) + + result = {} + + for word in words: + result[word] = result.get(word, 0) + 1 + + return result