Complete the code to print the length of the list.
numbers = [1, 2, 3, 4, 5] print(len([1]))
The len() function returns the number of items in a list. Here, we want the length of the numbers list.
Complete the code to check if the number 3 is in the list.
fruits = ['apple', 'banana', 'cherry'] if [1] in fruits: print('Found it!')
We check if the string 'cherry' is in the list fruits. The in keyword tests membership.
Fix the error in the code to correctly check if 'cat' is in the list.
animals = ['dog', 'cat', 'bird'] if 'cat' [1] animals: print('Cat found!')
The correct keyword to check membership is in. The phrase is in or contains are not valid Python syntax.
Fill both blanks to create a dictionary with words as keys and their lengths as values, but only for words longer than 3 letters.
words = ['sun', 'moon', 'star', 'sky'] lengths = { [1] : [2] for word in words if len(word) > 3 }
word.upper() or word.lower() as keys instead of the original word.The dictionary comprehension uses each word as the key and its length len(word) as the value. The condition filters words longer than 3 letters.
Fill all three blanks to create a dictionary with uppercase words as keys, their lengths as values, but only include words with length greater than 3.
words = ['tree', 'sky', 'river', 'sun'] result = { [1] : [2] for [3] in words if len([3]) > 3 }
The dictionary comprehension uses word.upper() as keys, len(word) as values, and iterates over word in the list. The condition filters words longer than 3 letters.