14 lines
267 B
Python
14 lines
267 B
Python
import re
|
|
|
|
|
|
def count_words(text):
|
|
words = re.findall(r"[^\W_]+(?:'[^\W_]+)?", text.lower(), re.UNICODE)
|
|
result = {}
|
|
|
|
for word in words:
|
|
if word in result:
|
|
result[word] += 1
|
|
else:
|
|
result[word] = 1
|
|
|
|
return result |