[Raymond Hettinger, on """ import heapq class Heap(list): def __init__(self, iterable=[]): self.extend(iterable) push = heapq.heappush popmin = heapq.heappop replace = heapq.heapreplace heapify = heapq.heapify """ ] > And perhaps: > def __iter__(self): > while True: > yield self.popmin() If we were trying to hide the list nature, yes, but I don't think so if the intent is that a heapq heap *is* a list with a few extra methods. For example, I know I've already done max(h) at least once for a Heap of this type, with the list meaning in mind, and it would have been at best irritating if that had emptied the heap as a side effect. Renaming __iter__ to heapiter would be cool, though!
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4