检查元组的 priorityQueue 中是否存在元素

check if element exists in priorityQueue of tuples

假设我有这个代码:

q = PriorityQueue()
a = ((1,1), 10, 0)
b = ((2,2), 99, 200)
q.push(a, 1)
q.push(b, 2)

我想检查元素 (1,1) 是否存在于队列中的任何元组中。有办法吗?

PriorityQueue 对象将其项目存储在可通过 queue attribute 访问的列表中。你可以这样做:

>>> q = PriorityQueue()
>>> a = ((1, 1), 10, 0)
>>> q.put(a)
>>> any((1, 1) in item for item in q.queue)
True