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