Aktualizovat u4/word_count.py

final
This commit is contained in:
Oleksandr Mateshchuk 2026-10-06 20:55:27 +00:00
parent a388452cc1
commit 1510578629

View File

@ -1,15 +1,14 @@
import re
text = input()
def count_words(text):
words = re.findall(r"[^\W_]+(?:'[^\W_]+)?", text.lower(), re.UNICODE)
counts = {}
result = {}
for word in words:
if word in counts:
counts[word] += 1
if word in result:
result[word] += 1
else:
counts[word] = 1
for word, count in sorted(counts.items()):
print(f"{word}: {count}")
result[word] = 1
return result