Quene

T

Tuvas

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))
quene.append((3,6))
if(4 in quene): #Shows false, what's the correct syntax to
show true?
remove 4 from quene #(Not python code, not sure how to do this...)


So, how can I make this work? Thanks!
 
D

Dave Hansen

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?

the following might work...
quene=[]
quene.append((4,2))
quene.append((3,6))
if(4 in quene): #Shows false, what's the correct syntax to
show true?

found = [t for t in queue if t[0] == 4]
if found:
remove 4 from quene #(Not python code, not sure how to do this...)
queue.remove(found[0])

HTH,
-=Dave
 
P

Peter Hansen

Tuvas said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top