Complete the code to split the sentence into words using the split method.
sentence = "Data science is fun" tokens = sentence.[1]()
The split() method breaks a string into a list of words based on spaces by default.
Complete the code to tokenize the sentence by splitting on commas.
sentence = "apple,banana,orange" tokens = sentence.[1](",")
The split(",") method splits the string at each comma, creating a list of fruits.
Fix the error in the code to tokenize the sentence into words.
sentence = "Hello world" tokens = sentence.[1](" ")
The split(" ") method splits the sentence at spaces, creating a list of words.
Complete the code to create a dictionary with words as keys and their lengths as values.
words = ['data', 'science', 'fun'] lengths = {word: [1] for word in words}
In dictionary comprehension, word: len(word) creates key-value pairs where keys are words and values are their lengths.
Fill all three blanks to create a dictionary of words and their lengths, including only words longer than 3 letters.
words = ['data', 'is', 'fun', 'science'] lengths = { [1] : [2] for word in words if [3] }
The dictionary comprehension uses word as key, len(word) as value, and filters words with length greater than 3.