Complete the code to convert all text to lowercase.
text = "Hello World!" processed_text = text.[1]()
Using lower() converts all characters in the string to lowercase, which is a common first step in text preprocessing.
Complete the code to split the text into words.
text = "Machine learning is fun" words = text.[1]()
The split() method breaks a string into a list of words using spaces by default.
Fix the error in the code to remove punctuation from the text.
import string text = "Hello, world!" clean_text = text.translate(str.maketrans('', '', [1]))
string.punctuation contains all punctuation characters. Removing them cleans the text.
Fill both blanks to create a list of words without stopwords.
stopwords = {'is', 'the', 'and'}
words = ['this', 'is', 'fun']
filtered = [word for word in words if word [1] stopwords]Using not in filters out words that are in the stopwords set.
Fill all three blanks to create a dictionary of word counts from a list.
words = ['apple', 'banana', 'apple'] word_counts = [1]((word, [2]) for word in words if words.count(word) [3] 1)
We use dict to create a dictionary, count each word with words.count(word), and filter words that appear more than once with >.