u4_repair

This commit is contained in:
Martin Škovran 2026-10-05 22:11:05 +02:00
parent bb461325fd
commit f9b7921fa6

View File

@ -1,17 +1,25 @@
from collections import defaultdict from collections import defaultdict
def count_words(sentance: str) -> dict: def count_words(sentance: str) -> dict:
words = defaultdict(0) words = defaultdict(int)
delims = [":", "?", "!", "\n", "\t"] delims = [":", "?", "!", "\n", "\t"]
for delim in delims: for delim in delims:
sentance = sentance.replace(delim, " ") sentance = sentance.replace(delim, " ")
for w in sentance.split(" "): del_chars = ['"', ",", "."]
words[w] += 1 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.'''))