We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
importres=input()pattern=r'(?<!")([.?!])(?!")'split_text=re.split(pattern,s)#merge back the sentence + last charactermerged_list=[split_text[i]+split_text[i+1]foriinrange(0,len(split_text)-1,2)]#check for words <= 2 and anding on a fullstop. These are like Dr. Mr. Ms. etc and merge these backnew_text=[]do_continue=Falseforiinrange(len(merged_list)-1):#print(i, "new_text: " , merged_list[i])ifdo_continue:do_continue=Falsecontinueiflen(merged_list[i].strip())<=3andmerged_list[i][-1]==".":new_text[-1]=new_text[-1]+" "+merged_list[i].strip()new_text[-1]=new_text[-1]+" "+merged_list[i+1].strip()#skip the next entry in the listdo_continue=Trueelse:new_text.append(merged_list[i])foriinnew_text:print(i)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
From Paragraphs to Sentences
You are viewing a single comment's thread. Return to all comments →