Python: word_count

This commit is contained in:
Dmitry Kokorin 2021-06-08 16:30:49 +03:00
parent 6223031c18
commit 0dd5b31529
4 changed files with 201 additions and 0 deletions

View file

@ -0,0 +1,9 @@
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)