class _PriorityQEntry: def __init__(self, item, priority): self.item = item self.priority = priority class PriorityQueue: def __init__(self): self._qList = list() def isEmpty(self): return len(self) == 0 def __len__(self): return len(self._qlist) def enqueue(self, item, priority): entry = _PriorityQEntry(item, priority) self._qList.append(entry) def dequeue(self): assert not self.isEmpty(), "Cannot dequeue from an empty queue" highest = self._qList[0].priority for i in range(self.len()): if self._qList[i] < highest: highest = self._qList[i].priority entry = self._qList.pop(i) return entry.item