Complete the code to convert all text in the list to lowercase.
texts = ['Hello World', 'Data Science'] lower_texts = [text.[1]() for text in texts] print(lower_texts)
The lower() method converts all characters in a string to lowercase.
Complete the code to remove leading and trailing spaces from each string.
texts = [' data ', ' science '] clean_texts = [text.[1]() for text in texts] print(clean_texts)
The strip() method removes spaces from the start and end of a string.
Fix the error in the code to remove punctuation from the text using string.punctuation.
import string text = 'Hello, world!' clean_text = ''.join(char for char in text if char not in [1]) print(clean_text)
The correct attribute for all punctuation characters is string.punctuation.
Fill both blanks to create a dictionary of word lengths for words longer than 3 characters.
words = ['data', 'is', 'fun', 'science'] lengths = {word: [1] for word in words if [2] print(lengths)
The dictionary comprehension maps each word to its length using len(word). The condition keeps words with length greater than 3 using len(word) > 3.
Fill all three blanks to create a dictionary of uppercase words and their lengths for words longer than 4 characters.
words = ['hello', 'data', 'science', 'fun'] result = { [1]: [2] for w in words if [3] } print(result)
The dictionary comprehension uses w.upper() as keys, len(w) as values, and filters words with length greater than 4.