13 lines
341 B
Python
13 lines
341 B
Python
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)) |