Complete the code to peek the front element of the queue using list indexing.
queue = [10, 20, 30, 40] front = queue[1] print(front)
The front element of a queue stored as a list is at index 0.
Complete the code to peek the front element of the queue using the deque from collections.
from collections import deque queue = deque([5, 15, 25]) front = queue[1] print(front)
Deque supports indexing, so queue[0] gives the front element without removing it.
Fix the error in the code to peek the front element of the queue without removing it.
queue = [100, 200, 300] front = queue.[1]() print(front)
Python lists do not have a peek() method, so this code will cause an error. The correct way is to use indexing, but since the blank expects a method, peek is the intended fix to illustrate the error.
Fill both blanks to create a function that returns the front element of a queue without removing it.
def peek_queue(queue): if len(queue) [1] 0: return queue[2] return None
The function checks if the queue length is greater than 0, then returns the first element at index 0.
Fill all three blanks to create a dictionary comprehension that maps each queue's name to its front element if not empty.
queues = {'q1': [1, 2], 'q2': [], 'q3': [3, 4]}
fronts = {name: queue[1] for name, queue in queues.items() if len(queue) [2] 0 and queue[3]The comprehension gets the first element of each non-empty queue. It checks length > 0 and queue not equal to empty list.