u4_repair_2_3
This commit is contained in:
parent
3da6c7bdb6
commit
9847f3cf6e
@ -4,7 +4,9 @@ def count_words(sentance: str) -> dict:
|
||||
sent_list = list(sentance)
|
||||
words = defaultdict(int)
|
||||
|
||||
delims = [":", "?", "!", "\n", "\t", ",", "."]
|
||||
SPECIAL_CHAR = oct(7)
|
||||
|
||||
delims = [":", "?", "!", "\n", "\t", ",", ".", "_"]
|
||||
del_chars = ['"']
|
||||
|
||||
forbidden = delims + del_chars + [" ", "'", ""]
|
||||
@ -16,13 +18,15 @@ def count_words(sentance: str) -> dict:
|
||||
sent_list[i] = ""
|
||||
if(ch == "'"):
|
||||
if((sent_list[max(i-1, 0)] not in forbidden) and (sent_list[min(i+1, len(sent_list)-1)] not in forbidden)):
|
||||
sent_list[i] = '^'
|
||||
sent_list[i] = SPECIAL_CHAR
|
||||
else:
|
||||
sent_list[i] = ""
|
||||
|
||||
for w in ''.join(sent_list).lower().split(" "):
|
||||
if w == "":
|
||||
continue
|
||||
words[w.replace("^", "'")] += 1
|
||||
words[w.replace(SPECIAL_CHAR, "'")] += 1
|
||||
|
||||
return dict(words)
|
||||
return dict(words)
|
||||
|
||||
print(count_words("""seriál: seriálik ako Dunaj: Panelák!!&@$%^&"""))
|
||||
Loading…
Reference in New Issue
Block a user