def __init__(self, initial=None, key=lambda x:x): self.__key = key if initial: self._data = [(key(item), item) for item in initial] heapq.heapify(self._data) else: self._data = []