import string from collections import Counter def count_words(sentence): text = sentence.lower() for mark in string.punctuation.replace("'", ""): text = text.replace(mark, " ") words = [] for word in text.split(): word = word.strip("'") if word: words.append(word) return dict(Counter(words))