Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to convert list to queue in python?

Tags:

How to convert a list to queue? So that operations like enqueue or dequeue an be carried out. I want to use to the list to remove the top most values and i believe it can be done using queues.

like image 822
rggod Avatar asked Feb 07 '14 23:02

rggod


Video Answer


1 Answers

pop from the front of a list is not very efficient as all the references in the list need to be updated.

deque will allow you do queue like operations efficiently

>>> from collections import deque >>> deque([1,2,3,4]) deque([1, 2, 3, 4]) 
like image 103
John La Rooy Avatar answered Oct 01 '22 13:10

John La Rooy