On Mar 8, 9:43 am, malkarouri <[EMAIL PROTECTED]> wrote:
> Hi everyone,
>
> I have an algorithm in which I need to use a loop over a queue on
> which I push values within the loop, sort of:
>
> while not(q.empty()):
>     x = q.get()
>     #process x to get zero or more y's
>     #for each y:
>     q.put(y)

Why not just do it like that?  With a few changes it'll work fine:

while q:
    x = q.pop(0)
    for y in process(x):
        q.append(y)


And consider collections.deque for q instead of a list, though it
shouldn't make much of a difference if the queue remains small.


Carl Banks
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to