-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path6.py
More file actions
36 lines (21 loc) · 718 Bytes
/
6.py
File metadata and controls
36 lines (21 loc) · 718 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
def word_count(text: str) -> dict[str, int]:
text = text.lower()
from collections import Counter
words = text.split()
freq = Counter(words)
a = dict()
for w, c in freq.items():
a.update({w:c})
return a
def main() -> None:
print("word_count('Hi hi HI') =>", word_count("Hi hi HI"))
print("word_count('one two two') =>", word_count("one two two"))
assert word_count("hI Hi HI") == {"hi": 3}
if __name__ == "__main__":
main()
def main() -> None:
print("word_count('Hi hi HI') =>", word_count("Hi hi HI"))
print("word_count('one two two') =>", word_count("one two two"))
assert word_count("Hi hi HI") == {"hi": 3}
if __name__ == "__main__":
main()