October 2018
Beginner to intermediate
398 pages
11h 1m
English
The dequeue operation is used to delete items from the queue. This method returns the topmost item from the queue and deletes it from the queue. Here is the implementation of the dequeue method:
def dequeue(self): data = self.items.pop() # delete the topmost item from the queue self.size -= 1 # decrement the size of the queue by 1 return data
The Python list class has a method called pop(). The pop method does the following:
The last item in the list is popped and saved in the data variable. In the last line of the method, the data is returned.
Consider the following figure as our queue implementation, ...