Complete the code to create a list that can store multiple items.
my_collection = [1]Lists in programming are like shopping bags where you can put many items in order. The square brackets [] create an empty list.
Complete the code to add a new item to the end of the list.
my_list = [1, 2, 3] my_list.[1](4)
insert requires a position index.add is for sets, not lists.extend adds multiple items from another list.The append method adds a single item to the end of a list, like putting a new book at the end of a shelf.
Fix the error in the code to access the value for key 'name' in the dictionary.
person = {'name': 'Alice', 'age': 30}
print(person[1]'name')Dictionaries use square brackets [] to access values by their keys, like looking up a word in a dictionary book.
Complete the code to create a dictionary comprehension that maps words to their lengths for words longer than 3 letters.
{word: len(word) for word in words if len(word) [1] 3}= instead of : causes syntax errors.< filters shorter words, not longer.In dictionary comprehensions, : separates keys and values. The condition > filters words longer than 3 letters.
Fill all three blanks to create a dictionary comprehension that maps uppercase keys to their values for items with positive values.
result = [1]: [2] for k, v in data.items() if v [3] 0}
k instead of k.upper() keeps keys unchanged.< filters negative values, not positive.This comprehension creates keys in uppercase using k.upper(), keeps values as v, and filters items with values greater than zero using >.