Quene

Peter Hansen peter at engcorp.com
Wed Nov 30 13:30:47 EST 2005


Tuvas wrote:
> I am trying to write a function that holds a variable-length quene. The
> quene has 2 bits of information. At some point, I would like to remove
> bits of this quene, when they are completed. Is there a way to do this
> with something as follows?
> 
> quene=[]
> quene.append((4,2))

Here you are not adding two items (a 4 and a 2) but only a single item 
(a tuple, containing within it a 4 and a 2).  What did you really want 
to do?

> quene.append((3,6))
> if(4 in quene):            #Shows false, what's the correct syntax to
> show true?

Since you don't have a 4 in your list, there is no correct syntax.  If 
you did have a 4, that would be the correct syntax, or you could use 
queue.index(4) instead if you cared *where* it was in the list.

>     remove 4 from quene #(Not python code, not sure how to do this...)

queue.pop(0) will pop an item off the front of the list, which is the 
end opposite where .append() puts them.

-Peter




More information about the Python-list mailing list