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