Open Anisha7 opened 4 years ago
enqueue
methods that was causing the problem.Try these tests for your priority queue to help you debug your push_pop() method:
if __name__ == '__main__':
test_priority_queue()
PQ = PriorityQueue()
assert(PQ.is_empty())
assert(PQ.length() == 0)
PQ.enqueue("apple", 2)
assert(PQ.length() == 1)
assert(PQ.front() == "apple")
assert(PQ.length() == 1)
PQ.enqueue("orange", 0)
assert(PQ.length() == 2)
assert(PQ.front() == "orange")
assert(PQ.length() == 2)
assert(PQ.dequeue() == "orange")
assert(PQ.length() == 1)
assert(PQ.push_pop("banana", 4) == "apple")
assert(PQ.length() == 1)
assert(PQ.front() == "banana")
assert(PQ.length() == 1)
print("PASSED")
You need to return the item, not the tuple.
Oh ok, sorry I overlooked it. I just needed to index the item in the tuple like so return self.heap.replace_min((priority, item))[1]
Great work on completing these challenges. Here's some feedback to improve your code:
TypeError: insert() takes exactly 2 arguments.
You're using your heap's insert method here, so check what parameters and in what order are given to this method.