mod u4
This commit is contained in:
parent
27305dd122
commit
85f4c96268
@ -1,14 +1,12 @@
|
|||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
def isalnum_without_apostroph(ch: str):
|
|
||||||
return ch.isalnum() and ch != "'"
|
|
||||||
def count_words(sentance: str) -> dict:
|
def count_words(sentance: str) -> dict:
|
||||||
sent_list = list(sentance)
|
sent_list = list(sentance)
|
||||||
words = defaultdict(int)
|
words = defaultdict(int)
|
||||||
|
|
||||||
for i, ch in enumerate(sent_list):
|
for i, ch in enumerate(sent_list):
|
||||||
if(ch == "'"):
|
if(ch == "'"):
|
||||||
if((isalnum_without_apostroph(sent_list[max(i-1, 0)])) and (isalnum_without_apostroph(sent_list[min(i+1, len(sent_list)-1)]))):
|
if((sent_list[max(i-1, 0)].isalnum()) and (sent_list[min(i+1, len(sent_list)-1)].isalnum())):
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
sent_list[i] = " "
|
sent_list[i] = " "
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user