Aktualizovat u4/word_count.py
This commit is contained in:
parent
01ecb88aa5
commit
a357fd6df5
@ -1,13 +1,14 @@
|
|||||||
import re
|
import re
|
||||||
from collections import Counter
|
|
||||||
|
|
||||||
|
text = input()
|
||||||
|
words = re.findall(r"[^\W_]+(?:'[^\W_]+)?", text.lower(), re.UNICODE)
|
||||||
|
counts = {}
|
||||||
|
|
||||||
def count_words(text):
|
for word in words:
|
||||||
text = text.replace("_", " ")
|
if word in counts:
|
||||||
text = text.replace("’", "'")
|
counts[word] += 1
|
||||||
pattern = r"[^\W_]+(?:'[^\W_]+)?"
|
else:
|
||||||
words = re.findall(pattern, text.lower())
|
counts[word] = 1
|
||||||
return dict(Counter(words))
|
|
||||||
|
|
||||||
|
for word, count in sorted(counts.items()):
|
||||||
word_count = count_words
|
print(f"{word}: {count}")
|
||||||
Loading…
Reference in New Issue
Block a user