如何检查Python队列中是否存在obj

时间:2018-06-29 04:05:31

标签: python python-3.x queue

如果一个对象存在于Python队列中,我正在寻找一件简单的事情

例如

queue = Queue.Queue()
queue.put(1)
queue.put(2)
queue.put(3)
queue.put(4)

if 3 in queue:
     print "yes"

我遇到错误;

  

回溯(最近通话最近一次):

     

文件“”,位于

的第1行      

TypeError:“ instance”类型的参数不可迭代

我是Python的新手,但我知道它很容易用Java处理。

Queue<Integer> q = new LinkedList<>();
//here is the method
q.contains(obj)

我没有任何解决方案来处理这种情况,这是我的Python问题之一。 如果有人可以帮助,我将不胜感激。

-克里希纳

0 个答案:

没有答案