• + 0 comments
    import re
    s = input()
    
    
    pattern = r'(?<!")([.?!])(?!")'
    split_text = re.split(pattern, s)
    #merge back the sentence + last character
    merged_list = [split_text[i] + split_text[i + 1] for i in range(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 back
    new_text = []
    do_continue = False
    for i in range(len(merged_list) - 1):
        #print(i, "new_text: " , merged_list[i])
        if do_continue:
            do_continue = False
            continue
            
        if len(merged_list[i].strip()) <= 3 and merged_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 list
            do_continue = True
        else:
            new_text.append(merged_list[i])
            
    for i in new_text:   
         print(i)