From dab28d5075cb6db52c5cc4a5ab709a2d67c20923 Mon Sep 17 00:00:00 2001 From: Arina Dohadailo Date: Tue, 6 Oct 2026 12:21:21 +0000 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=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 | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/u4/word_count.py b/u4/word_count.py index 1125029..21505f4 100644 --- a/u4/word_count.py +++ b/u4/word_count.py @@ -1,13 +1,16 @@ import string -from collections import Counter + + def count_words(sentence): + counts = {} text = sentence.lower() -for mark in string.punctuation.replace("'", ""): + + for mark in string.punctuation.replace("'", ""): text = text.replace(mark, " ") -words = [] + for word in text.split(): word = word.strip("'") if word: - words.append(word) + counts[word] = counts.get(word, 0) + 1 - return dict(Counter(words)) \ No newline at end of file + return counts \ No newline at end of file