Complete the code to add an item to the end of the queue.
queue = [] queue.[1]('apple')
To add an item to the end of a list (queue), we use append. This keeps the first-in, first-out order.
Complete the code to remove the first item from the queue.
queue = ['apple', 'banana', 'cherry'] first_item = queue.[1](0)
To remove the first item from the queue, use pop(0). This removes and returns the item at index 0, following FIFO.
Fix the error in the code to correctly remove the first item from the queue.
queue = ['dog', 'cat', 'bird'] removed = queue.[1]
The pop method needs the index to remove the first item. pop(0) removes the first element. pop() without arguments removes the last item.
Fill both blanks to create a queue comprehension that keeps only items longer than 3 characters.
queue = ['cat', 'lion', 'dog', 'tiger'] filtered = [item for item in queue if len(item) [1] [2]]
The comprehension keeps items where the length is greater than 3, so use len(item) > 3.
Fill all three blanks to create a dictionary showing each item and its position in the queue.
queue = ['red', 'blue', 'green'] positions = [1]: [2] for [3], color in enumerate(queue)}
The dictionary comprehension uses {color: index for index, color in enumerate(queue)} to map each color to its position.