Re: queue versus list

2020-03-20 Thread duncan smith
On 20/03/2020 21:57, Barry wrote: > > >> On 20 Mar 2020, at 00:42, duncan smith wrote: >> >> Bingo. Performance is indistinguishable from that of the list. Thread >> safety is unimportant (for my purposes), but the docs at >> https://docs.python.org/2/library/collections.html#collections.deque

Re: queue versus list

2020-03-20 Thread Cameron Simpson
On 20Mar2020 06:50, Dan Stromberg wrote: Actually, I think a deque is a doubly linked list of python lists. On 20Mar2020 09:45, Antoon Pardon wrote: This doesn't seem correct. A deque is used to simulate a stack or a queue. It doesn't use heappush or heappop. You are both correct; brain

Re: queue versus list

2020-03-20 Thread Barry
> On 20 Mar 2020, at 00:42, duncan smith wrote: > > Bingo. Performance is indistinguishable from that of the list. Thread > safety is unimportant (for my purposes), but the docs at > https://docs.python.org/2/library/collections.html#collections.deque > state "Deques support thread-safe,

Re: queue versus list

2020-03-20 Thread Dan Sommers
On Fri, 20 Mar 2020 06:50:29 -0700 Dan Stromberg wrote: > On Thu, Mar 19, 2020 at 6:11 PM Cameron Simpson wrote: > > > >> 4. If it doesn't need to be thread-safe, why not try deques instead? > > > > > >Bingo. Performance is indistinguishable from that of the list. > > > > A deque is implement

Re: queue versus list

2020-03-20 Thread Dan Stromberg
On Thu, Mar 19, 2020 at 6:11 PM Cameron Simpson wrote: > >> 4. If it doesn't need to be thread-safe, why not try deques instead? > > > >Bingo. Performance is indistinguishable from that of the list. > > A deque is implement using a list. > Actually, I think a deque is a doubly linked list of

Re: queue versus list

2020-03-20 Thread Antoon Pardon
Op 20/03/20 om 02:10 schreef Cameron Simpson: On 20Mar2020 00:37, duncan smith wrote: Thread safety is unimportant (for my purposes), but the docs at https://docs.python.org/2/library/collections.html#collections.deque state "Deques support thread-safe, memory efficient appends and pops

Re: queue versus list

2020-03-19 Thread Cameron Simpson
On 20Mar2020 00:37, duncan smith wrote: On 19/03/2020 20:40, MRAB wrote: On 2020-03-19 20:08, duncan smith wrote:    I have generator code along the following lines, Q = queue.Queue() Q.put(x) while not Q.empty(): x = Q.get() if : yield x else:    Q.put() If

Re: queue versus list

2020-03-19 Thread duncan smith
On 19/03/2020 20:40, MRAB wrote: > On 2020-03-19 20:08, duncan smith wrote: >> Hello, >>    I have generator code along the following lines, >> >> >> Q = queue.Queue() >> Q.put(x) >> while not Q.empty(): >> x = Q.get() >> if : >> yield x >> else: >>    Q.put() >> >>

Re: queue versus list

2020-03-19 Thread MRAB
On 2020-03-19 20:08, duncan smith wrote: Hello, I have generator code along the following lines, Q = queue.Queue() Q.put(x) while not Q.empty(): x = Q.get() if : yield x else: Q.put() If I change it to, Q = [] Q.append(x) for x in Q: if :

queue versus list

2020-03-19 Thread duncan smith
Hello, I have generator code along the following lines, Q = queue.Queue() Q.put(x) while not Q.empty(): x = Q.get() if : yield x else: Q.put() If I change it to, Q = [] Q.append(x) for x in Q: if : yield x else: Q.append() then it runs