Python 2.x, appending a PriorityQueue with another PriorityQueue

100 Views Asked by At

I am using Queue.PriorityQueue() in my problem in which I have several PriorityQueue() objects that I would like to append together by the priority based element.

All the PriorityQueue() objects have the same type in tuples that the PriorityQueue() objects are composed of.

Is there are a way (a pythonic way?) to do this without having to write my own code for this?

1

There are 1 best solutions below

1
On
def merge_queues(queues):    
    result_queue = PriorityQueue()
    for queue in queues:
        while not queue.empty():
            result_queue.put(queue.get())
    return result_queue