9 lines
228 B
Python
9 lines
228 B
Python
from collections import Counter
|
|
import re
|
|
|
|
WORDS_REGEXP = re.compile(r"([^\W_]+('[^\W_]+)?)")
|
|
|
|
|
|
def count_words(sentence):
|
|
words = [value[0].lower() for value in re.findall(WORDS_REGEXP, sentence)]
|
|
return Counter(words)
|