#!/usr/bin/env python3
# -*- coding: utf-8 -*-
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

    def pop(self):
        return heapq.heappop(self._queue)[-1]


class Item:
    def __init__(self, name):
        self.name = name

    def __repr__(self):
        return 'Item({!r})'.format(self.name)

a = Item('foo')
b = Item('bar')
c = Item('zoo')
q = PriorityQueue()
q.push(a, 1)
q.push(b, 2)
q.push(c, 5)
q.push(Item('tank'), 2)
q.push(Item('mike'), 3)
print(q.pop())
print(q.pop())
print(q.pop())
print(q.pop())
print(q.pop())

#   print(a < b)    TypeError: unorderable types: Item() < Item()
aa = (1, a)
bb = (1, b)
#   print(aa < bb)  TypeError: unorderable types: Item() < Item()
bb = (2, b)
print(aa < bb)      # True
