From 9e788e4652d9fa805d25ebfc6bf3e12e75398c6b Mon Sep 17 00:00:00 2001 From: Arina Dohadailo Date: Tue, 6 Oct 2026 12:08:19 +0000 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20u4.word=5Fcount.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- u4.word_count.py | 8 ++++++++ 1 file changed, 8 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..b97615c --- /dev/null +++ b/u4.word_count.py @@ -0,0 +1,8 @@ +def count_words(sentence): + cleaned = "".join(c if c.isalnum() or c == "'" else " " for c in sentence.lower()) + counts = {} + for word in cleaned.split(): + word = word.strip("'") + if word: + counts[word] = counts.get(word, 0) + 1 + return counts \ No newline at end of file