human
Write me a the Python code you requested given the following:
I am working on the file "1c_Python_Cookbook_3/Chapter_1.ipynb".
The first task is:
Discussion
When looking for N smallest/largest numbers, heapq provides superior performance. heap[0] is always the smallest number. Structures are converted into a list where items are ordered as a heap (underneath).

1.5 Implementing a Priority Queue
Problem:
Implement a queue that sorts items by a given priority and always returns the item with the highest priority on each pop operations.

Solution:
Use heapq to implement a simple priority queue
Can you write Python code for it?
assistant
#Here is the Python code you requested.

import heapq

class PriorityQueue:
    def __init__(self):
        self._queue = []
        self._index = 0
        
    def __repr__(self):
        return 'PriorityQueue({}) with index({})'.format(self._queue, self._index)
        
    def push(self, item, priority):
        heapq.heappush(self._queue, (-priority, self._index, item)) # heappush(list, ())
        self._index += 1
        
    def pop(self):
        return heapq.heappop(self._queue)[-1] # self_queue includes [(priority, index, item)] 
    
class Item:
    def __init__(self, name):
        self.name = name
        
    def __repr__(self):
        return 'Item({!r})'.format(self.name)
    
q = PriorityQueue()
print(q)
q.push(Item('foo'), 1)
print(q)
q.push(Item('bar'), 5)
print(q)
q.push(Item('spam'), 4)
print(q)
q.push(Item('grok'), 1)
print(q)
q.pop() # -> Item('bar')
print(q)
q.pop() # -> Item('spam')
print(q)
q.pop() # -> Item('foo')
print(q)
q.pop() # -> Item('grok')
print(q)

# foo and grok were popped in the same order in which they were inserted