I'm searching for a kind of priority queue which allows me to give two priorites. I want that it just check for the first value then for the second one Here is some Code
import Queue
class Job(object):
def __init__(self, fpriority, spriority, description, iata , hops, cost):
self.fpriority = fpriority
self.spriority = spriority
q = Queue.PriorityQueue()
q.put(Job(2, 5, 'Mid-level job'))
q.put(Job(2, 20, 'Low-level job'))
q.put(Job(1, 20, 'Important job'))
now i want the following order of the elements
Important job
Mid_level job
Low_level job
how can i create such an order with one queue?
Just use the (fpriority, spriority)
tuple as the priority. That'll do the sorting you want (compare first, then second to break ties).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With