diff --git a/u4/word_count.py b/u4/word_count.py index b97615c..1125029 100644 --- a/u4/word_count.py +++ b/u4/word_count.py @@ -1,8 +1,13 @@ +import string +from collections import Counter def count_words(sentence): - cleaned = "".join(c if c.isalnum() or c == "'" else " " for c in sentence.lower()) - counts = {} - for word in cleaned.split(): + text = sentence.lower() +for mark in string.punctuation.replace("'", ""): + text = text.replace(mark, " ") +words = [] + for word in text.split(): word = word.strip("'") if word: - counts[word] = counts.get(word, 0) + 1 - return counts \ No newline at end of file + words.append(word) + + return dict(Counter(words)) \ No newline at end of file