Complete the code to create a summary by selecting the first sentence.
text = "Machine learning helps computers learn from data. It improves tasks automatically." summary = text.split('. ')[[1]]
The first sentence is at index 0 in the split list, so selecting index 0 gives the summary.
Complete the code to count the number of words in the summary.
summary = "Machine learning helps computers learn from data" word_count = len(summary.[1]())
Splitting the summary by spaces creates a list of words. Counting this list gives the word count.
Fix the error in the code to generate a summary by joining the first two sentences.
text = "AI is a field of computer science. It focuses on creating smart machines." summary = '. '.join(text.split('. ')[:[1]])
To include the first two sentences, slice up to index 2 (not 1) because slicing excludes the end index.
Fill both blanks to create a dictionary of sentence lengths for sentences longer than 5 words.
text = "Summarization reduces text length. It keeps important info." sentences = text.split('. ') lengths = {sentence: len(sentence.[1]()) for sentence in sentences if len(sentence.[2]()) > 5}
Splitting each sentence into words counts the words. The dictionary stores sentence and its word count if more than 5 words.
Fill all three blanks to create a summary dictionary with sentence keys in uppercase and word counts greater than 3.
text = "Summarization condenses information. It helps understand quickly." sentences = text.split('. ') summary = {sentence.[1](): len(sentence.[2]()) for sentence in sentences if len(sentence.[3]()) > 3}
Uppercase the sentence keys, split sentences to count words, and check word count > 3 using split.