Question: Python string slicing using indexes, .find and . replace operators: def process_long_sentences(sentence): String slicing: Finish this function which takes a string as input and
Python string slicing using indexes, .find and . replace operators:
def process_long_sentences(sentence): """ String slicing: Finish this function which takes a string as input and return the first 40 characters of the original string and "..." if the string is more than 45 characters long. Otherwise, this function returns the original string. """ def split_paragraph_into_sentences(paragraph): """ Splitting a long string: Finish this function which takes a string as input and split the long string into sentences. If any sentence is too long, you should call the process_long_sentences function to replace the long sentence(s) with the shorter version(s). The return value should be a list of strings (shortened sentences). You can consider to use ". " as delimiter. Hint: you can call the process_long_sentences function to shorten a sentence. """ def split_paragraph_into_keyword_sentences(paragraph, keyword): """ Splitting a long string and only keep the sentences with the wanted keyword: The requirement for this function is similar to Question 02, but this time we only keep the sentence which contains the keyword. """ #============================== # test long_str_1 = """The traditional professions open to college graduateslaw, the church, business, medicinedid not interest Thoreau,[25]:25 so in 1835 he took a leave of absence from Harvard, during which he taught school in Canton, Massachusetts.""" short_str_1 = """Do you keep a journal?""" print(process_long_sentences(long_str_1)) print(process_long_sentences(short_str_1)) print("--"*10) #test long_str_2 = """The traditional professions open to college graduateslaw, the church, business, medicinedid not interest Thoreau, so in 1835 he took a leave of absence from Harvard, during which he taught school in Canton, Massachusetts. After he graduated in 1837, he joined the faculty of the Concord public school, but he resigned after a few weeks rather than administer corporal punishment. He and his brother John then opened the Concord Academy, a grammar school in Concord, in 1838. They introduced several progressive concepts, including nature walks and visits to local shops and businesses. The school closed when John became fatally ill from tetanus in 1842 after cutting himself while shaving. He died in Henry's arms.""" print(split_paragraph_into_sentences(long_str_2)) print(len(split_paragraph_into_sentences(long_str_2))) # hint: there are 6 sentences. print("--"*10) # test print(split_paragraph_into_keyword_sentences(long_str_2, "school")) print(len(split_paragraph_into_keyword_sentences(long_str_2, "school"))) # hint: there are 4 sentences. print("--"*10) Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
