import string def count_words(sentence): counts = {} text = sentence.lower() for mark in string.punctuation.replace("'", ""): text = text.replace(mark, " ") for word in text.split(): word = word.strip("'") if word: counts[word] = counts.get(word, 0) + 1 return counts