13 lines
279 B
Python
13 lines
279 B
Python
import re
|
||
from collections import Counter
|
||
|
||
|
||
def count_words(text):
|
||
text = text.replace("_", " ")
|
||
text = text.replace("’", "'")
|
||
pattern = r"[^\W_]+(?:'[^\W_]+)?"
|
||
words = re.findall(pattern, text.lower())
|
||
return dict(Counter(words))
|
||
|
||
|
||
word_count = count_words |