human
I am working on the file "A2/search_notebook.ipynb".
The first task is:
Warmups
We'll start by implementing some simpler search and optimization methods before the real exercises.
Warmup 1: Priority queue
5 points
In all searches that involve calculating path cost or heuristic (e.g. uniform-cost), we have to order our search frontier. It turns out the way that we do this can impact our overall search runtime. 
To show this, you'll implement a priority queue and demonstrate its performance benefits. For large graphs, sorting all input to a priority queue is impractical. As such, the datastructure you implement should have an amortized O(1) insertion and removal time. It should do better than the queue you've been provided in InsertionSortQueue().
Hints: 
1. The heapq module has been imported for you.
2. Each edge has an associated weight.
Can you write Python code for it?
assistant
#Here is the Python code you requested.

import heapq

class PriorityQueue():
    """Implementation of a priority queue 
    to store nodes during search."""
    
    # HINT look up the module heapq.

    def __init__(self):
        self.queue = []
        self.current = 0 

    def next(self):
        if self.current >=len(self.queue):
            self.current
            raise StopIteration
    
        out = self.queue[self.current]
        self.current += 1

        return out

    def pop(self):
        return heapq.heappop(self.queue)

    def __iter__(self):
        return self

    def __str__(self):
        return 'PQ:[%s]'%(', '.join([str(i) for i in self.queue]))

    def append(self, node):
        heapq.heappush(self.queue, node)
        
    #def push(self,cost,node,path):
        # TODO: finish this

    def __contains__(self, key):
        self.current = 0
        return key in [n for v,n in self.queue]

    def __eq__(self, other):
        return self == other
    
    def clear(self):
        self.queue = []
        
    #def has_element(self, element):
    __next__ = next

from search_tests import priority_queue_tests

priority_queue_tests(PriorityQueue)