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