Python deque tutorial (mathspp.com)
from learnbyexample@programming.dev to python@programming.dev on 18 Mar 2024 11:55
https://programming.dev/post/11620659

#python

threaded - newest

wewbull@feddit.uk on 18 Mar 2024 17:48 collapse

Maybe it’s just the type of problems I work on, but I never find myself wanting a deque. A queue, absolutely. A stack, sometimes, A priority queue, occasionally.

Never a deque.

neo@lemmy.hacktheplanet.be on 18 Mar 2024 21:37 next collapse

I use a deque to fill a queue from the right, items get consumed from the left. Sometimes feedback from an external control mechanism will request an item be added to the queue with high priority. This item is then added to the left of the queue and will get consumed next, before all the others already in the queue. For me this was a good use case for a deque and it works well.

sugar_in_your_tea@sh.itjust.works on 19 Mar 2024 00:35 next collapse

Same, but I also almost never use a stack or a priority queue. A list works like a stack if I ever need it (haven’t yet), and if I’m reaching for a priority queue, I likely want something more complex like an actual scheduler or something (e.g. a timeout with a priority).

But I have at least used those once or twice. I’ve never used a deque as a deque, only as a queue.

BehindTheBarrier@programming.dev on 19 Mar 2024 07:22 collapse

If you want a first in first out it’s better than a list. Deque is also whats powering thread safe queues in python where you want said FIFO functionality when sending from one thread to another. (typically the order doesn’t matter since it’s threads, but generally speaking it makes more sense to take the first thing going in, out of it too.)