Aktualizovat u4/word_count.py
final
This commit is contained in:
parent
a388452cc1
commit
1510578629
@ -1,15 +1,14 @@
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
text = input()
|
|
||||||
words = re.findall(r"[^\W_]+(?:'[^\W_]+)?", text.lower(), re.UNICODE)
|
|
||||||
counts = {}
|
|
||||||
|
|
||||||
for word in words:
|
def count_words(text):
|
||||||
if word in counts:
|
words = re.findall(r"[^\W_]+(?:'[^\W_]+)?", text.lower(), re.UNICODE)
|
||||||
counts[word] += 1
|
result = {}
|
||||||
|
|
||||||
|
for word in words:
|
||||||
|
if word in result:
|
||||||
|
result[word] += 1
|
||||||
else:
|
else:
|
||||||
counts[word] = 1
|
result[word] = 1
|
||||||
|
|
||||||
for word, count in sorted(counts.items()):
|
|
||||||
print(f"{word}: {count}")
|
|
||||||
|
|
||||||
|
return result
|
||||||
Loading…
Reference in New Issue
Block a user