python两个中文队列比较_具有两个优先级的优先级队列Python
使用NPE的策略-一個tuple作為隊列優(yōu)先級,tuple是(fpriority, spriority):import Queue
class Job(object):
def __init__(self, fpriority, spriority, description='blah', iata='foo' , hops='ample', cost='free pitchers'):
self.fpriority = fpriority
self.spriority = spriority
self.description = description
@property
def priority(self):
return (self.fpriority, self.spriority)
def __str__(self):
return self.description
q = Queue.PriorityQueue()
second = Job(2, 5, 'Mid-level job')
third = Job(2, 20, 'Low-level job')
first = Job(1, 20, 'Important job')
q.put((second.priority, second))
q.put((third.priority, third))
q.put((first.priority, first))
while q.unfinished_tasks:
task = q.get()
print task, task[1]
q.task_done()
>>>
((1, 20), <__main__.job object at>) Important job
((2, 5), <__main__.job object at>) Mid-level job
((2, 20), <__main__.job object at>) Low-level job
>>>
這對優(yōu)先級元組中的任意數(shù)量的項都有效。在
^{pr2}$
總結(jié)
以上是生活随笔為你收集整理的python两个中文队列比较_具有两个优先级的优先级队列Python的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: math.pow int_Java Ma
- 下一篇: 物联网计算机相关专业吗,物联网工程属于计