u4
This commit is contained in:
parent
0f5085b5df
commit
bb461325fd
17
u4/word_count.py
Normal file
17
u4/word_count.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
from collections import defaultdict
|
||||||
|
|
||||||
|
def count_words(sentance: str) -> dict:
|
||||||
|
words = defaultdict(0)
|
||||||
|
|
||||||
|
delims = [":", "?", "!", "\n", "\t"]
|
||||||
|
|
||||||
|
for delim in delims:
|
||||||
|
sentance = sentance.replace(delim, "")
|
||||||
|
|
||||||
|
for w in sentance.split(" "):
|
||||||
|
words[w] += 1
|
||||||
|
|
||||||
|
return words
|
||||||
|
|
||||||
|
print(count_words(""""To je heslo: 'HESLO 123'!", zvolala postava zo seriálu Panelák.\nPotom som utiekol."""))
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user