exercism-solutions/python/word-count/word_count.py
2021-06-08 16:30:49 +03:00

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)