2
In the code:
import heapq
class PriorityQueue:
def __init__(self):
self._queue = []
self._index = 0
def push(self, item, priority):
heapq.heappush(self._queue, (-priority, self._index, item))
self._index += 1
class Person:
def __init__(self,name):
self.name = name
def __repr__(self):
return self.name
lista = PriorityQueue()
lista.push(Person('Dener'), 30)
lista.push(Person('Rodrigo'), 25)
lista.push(Person('Lucas'), 22)
I don’t really understand how the method works:
def push(self, item, priority):
heapq.heappush(self._queue, (-priority, self._index, item))
self._index += 1
Could someone explain to me?
It seems to me that one is missing
)
somewhere.– Lacobus
I’ve already edited @Lacobus
– Lucas Moraes
@Lucasmoraes you could explain me if your code runs and you just want a help to understand the method, or the code presents some error
– Victor