avp26/u4/word_count.py

14 lines
285 B
Python

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