Aktualizovat u4/word_count.py
This commit is contained in:
parent
5e7f009659
commit
2bf60cfd3b
@ -1,10 +1,13 @@
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
def count_words(text):
|
def count_words(text):
|
||||||
words = re.findall(r"\b[\w]+(?:'[\w]+)?\b", text.lower(), re.UNICODE)
|
words = re.findall(r"[^\W_]+(?:'[^\W_]+)?", text.lower(), re.UNICODE)
|
||||||
result = {}
|
result = {}
|
||||||
|
|
||||||
for word in words:
|
for word in words:
|
||||||
result[word] = result.get(word, 0) + 1
|
if word in result:
|
||||||
|
result[word] += 1
|
||||||
|
else:
|
||||||
|
result[word] = 1
|
||||||
|
|
||||||
return result
|
return result
|
||||||
Loading…
Reference in New Issue
Block a user