I am practicing doing programming competitions using python(actually pypy3). For a problem I need to use a queue - I only need to put at one end and pop from the other. From what I found in the documentation it seems I have two options queue.Queue
and queue.deque
. I first tried the problem using queue.Queue, but my solution exceeded the time limit. Then I switched to queue.deque
and I passed the problem(though close to the limit).
From the documentation it seems both containers are thread safe(well at least for some operations for deque) while for my situation I will never use more than one thread. Is there a simple non-synchronized queue built-in in python?
collections.deque
? – PM 2RingDeques support thread-safe, memory efficient appends and pops from either side of the deque with approximately the same O(1) performance in either direction.
– Ivaylo Strandjevqueue.Queue
(akaQueue.Queue
in Python 2) uses acollections.deque
internally; if you don't need the special features ofqueue.Queue
you should be using a plaincollections.deque
. – PM 2Ring