Complete the code to change the first item of the list to 10.
numbers = [1, 2, 3] numbers[0] = [1] print(numbers)
Lists are mutable, so you can change an item by assigning a new value to its index. Here, we assign 10 to the first item.
Complete the code to add the number 4 at the end of the list.
numbers = [1, 2, 3] numbers.[1](4) print(numbers)
insert without specifying the index.extend which expects an iterable, not a single item.The append method adds a single item to the end of the list.
Fix the error in the code to change the second item to 20.
numbers = [5, 6, 7] numbers[[1]] = 20 print(numbers)
List indexes start at 0, so the second item is at index 1.
Fill both blanks to create a new list with squares of numbers greater than 2.
numbers = [1, 2, 3, 4, 5] squares = [x[1]2 for x in numbers if x [2] 2] print(squares)
% which is modulo, not power.+ which adds numbers instead of squaring.Use ** to square numbers and > to filter numbers greater than 2.
Fill all three blanks to create a dictionary with uppercase keys and values greater than 3.
numbers = {'a': 1, 'b': 4, 'c': 5}
result = [1]: [2] for [3], v in numbers.items() if v > 3}
print(result)v.upper() which is invalid because values are integers.k instead of k.upper() for keys.Use k.upper() for uppercase keys, v for values, and k as the loop variable for keys.
