I recently decided to work with Python 3 and I have questions regarding queues. As far as I understand the queue in the queue library is adapted for multithreaded programs. I assume that that queue is not as efficient as the simple queue (if I am wrong please correct). Therefore, I found that there is a deque from collections library which resembles deque in C++. Am I right that that's what competitive Python programmers use (for example, BFS problems)?








I program mostly in pypy and this is what i used for bfs.
Deque with popleft can easily replace queue and is fast for unbounded queue as it require no locking.
Another Alternative is to use Queue module itself
Useful Link
deque is the right queue for algorithms. Don't use Queue it is for communication between threads.
You can read the source code for Python 3
queuemodule here.As you can see from source,
Queueclass adds locks forputandgetmethods. If you just want a simple double ended queue, you should usedequefromcollectionsmodule. EvenQueueusesdequeinternally.You are right in assuming that
Queueis not as efficient asdequeanddequeis what Python programmers use.