假设我有这段代码:
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
关于python - 检查元组的 priorityQueue 中是否存在元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46223338/