Python: word_count
This commit is contained in:
parent
6223031c18
commit
0dd5b31529
4 changed files with 201 additions and 0 deletions
9
python/word-count/word_count.py
Normal file
9
python/word-count/word_count.py
Normal 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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue