Skip to main contentSkip to solution

What is the purpose of the following function?

def fun(mydeque):

if not (isEmpty()):

return mydeque[0]

else:

print("empty")

Solution

✅ Correct Option: 4

The function first checks that the deque is not empty. It then returns mydeque[0], which is the element at the front, and does not change the deque. If the deque is empty, it prints "empty". This is the peek (getFront) operation: it reads the front value without removing it.


Options 1 and 3: insertion needs append() or appendleft()-style operations that change the deque, but this function only reads an index.

Option 2: deletion needs a removal such as pop() or del, and mydeque[0] is the front, not the rear (the rear is mydeque[-1]).

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question