Yes, it is possible.
Let's say you have a list:
k = [3,2,6,4,9]
Now, let's say you want to print out the max element first(or any other element with the maximum priority). Then the logic is to reverse the priority by multiplying it with -1
, then use the PriorityQueue
class object which supports the min priority queue for making it a max priority queue.
For example:
k = [3,2,6,4,9]
q = PriorityQueue()
for idx in range(len(k)):
# We are putting a tuple to queue - (priority, value)
q.put((-1*k[idx], idx))
# To print the max priority element, just call the get()
# get() will return tuple, so you need to extract the 2nd element
print(q.get()[1]
NB: Library is queue.PriorityQueue
in Python3