Re: List as FIFO in for loop

2008-03-10 Thread Arnaud Delobelle
On Mar 8, 2:43 pm, 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: >    

Re: List as FIFO in for loop

2008-03-10 Thread rockingred
On Mar 8, 5:37 pm, malkarouri <[EMAIL PROTECTED]> wrote: > On Mar 8, 6:24 pm, rockingred <[EMAIL PROTECTED]> wrote: > > > I think it's a bad practice to get into.  Did you intend to do the > > "process" step again over the added variables?  If not I would set a > > new variable, based on your awful

Re: List as FIFO in for loop

2008-03-08 Thread Paul Hankin
On Mar 8, 10:42 pm, Carl Banks <[EMAIL PROTECTED]> wrote: > 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

Re: List as FIFO in for loop

2008-03-08 Thread Carl Banks
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: >

Re: List as FIFO in for loop

2008-03-08 Thread malkarouri
On Mar 8, 6:24 pm, rockingred <[EMAIL PROTECTED]> wrote: > I think it's a bad practice to get into.  Did you intend to do the > "process" step again over the added variables?  If not I would set a > new variable, based on your awful naming convention, let's call it z. > Then use z.append(y) within

Re: List as FIFO in for loop

2008-03-08 Thread malkarouri
On Mar 8, 4:44 pm, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote: ... > Notice that the language specification *deliberately* does not > distinguish between deletion of earlier and later items, but > makes modification of the sequence undefined behavior to allow > alternative implementations. E.g. an

Re: List as FIFO in for loop

2008-03-08 Thread castironpi
> Notice that the language specification *deliberately* does not > distinguish between deletion of earlier and later items, but > makes modification of the sequence undefined behavior to allow > alternative implementations. E.g. an implementation that would > crash, erase your hard disk, or set you

Re: List as FIFO in for loop

2008-03-08 Thread rockingred
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: >    

Re: List as FIFO in for loop

2008-03-08 Thread Martin v. Löwis
> Still, why avoid changing loop variable? Does python treat looping > over a list differently from looping over an iterator, where it > doesn't know if the iterator future changes while loop running? Take a look at Objects/listobject.c:listiterobject. It contains an it_index, which is the index i

Re: List as FIFO in for loop

2008-03-08 Thread malkarouri
On Mar 8, 3:52 pm, duncan smith <[EMAIL PROTECTED]> wrote: > malkarouri 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

Re: List as FIFO in for loop

2008-03-08 Thread malkarouri
On Mar 8, 3:20 pm, Roel Schroeven <[EMAIL PROTECTED]> wrote: > malkarouri schreef: > > > > > 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 g

Re: List as FIFO in for loop

2008-03-08 Thread duncan smith
malkarouri 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) > > The easiest thing I ca

Re: List as FIFO in for loop

2008-03-08 Thread Roel Schroeven
malkarouri schreef: > 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) > > The easiest thing I

List as FIFO in for loop

2008-03-08 Thread malkarouri
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) The easiest thing I can do is use a list as a queue and a normal