Complete the code to add a new item to the list without removing existing items.
my_list = [1, 2, 3] my_list.[1](4) print(my_list)
The append method adds a single item to the end of the list without removing existing items.
Complete the code to replace the value of the key 'name' in the dictionary.
person = {'name': 'Alice', 'age': 30}
person['name'] = [1]
print(person)Assigning a new value to person['name'] overwrites the old value.
Fix the error in the code to add a new key-value pair to the dictionary without overwriting existing keys.
settings = {'volume': 5, 'brightness': 7}
settings.[1]({'contrast': 10})
print(settings)The update method adds new key-value pairs or updates existing keys without removing other keys.
Fill both blanks to create a dictionary with word lengths only for words longer than 3 letters.
words = ['cat', 'house', 'dog', 'elephant'] lengths = {word: [1] for word in words if len(word) [2] 3} print(lengths)
We use len(word) to get the length and filter words with length greater than 3 using >.
Fill all three blanks to create a dictionary with uppercase keys and values only if the value is greater than 0.
data = {'a': 1, 'b': 0, 'c': 3}
result = [1]: [2] for k, v in data.items() if v [3] 0
print(result)Keys are converted to uppercase with k.upper(), values are v, and we filter values greater than 0 using >.