Aktualizovat u4/word_count.py
final
This commit is contained in:
parent
a388452cc1
commit
1510578629
@ -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
|
||||
Loading…
Reference in New Issue
Block a user