Bugs item #1158313, was opened at 2005-03-07 15:15 Message generated for change (Tracker Item Submitted) made by Item Submitter You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1158313&group_id=5470
Category: Python Library Group: Feature Request Status: Open Resolution: None Priority: 5 Submitted By: Stefan Behnel (scoder) Assigned to: Nobody/Anonymous (nobody) Summary: heapq should provide iterators: itersmallest, iterlargest Initial Comment: The current C-based heapq implementation provides implementations of min-heaps and max-heaps for the "nsmallest" and "nlargest" functions. I would like to see them used to provide iterators over the smallest/largest items of a heap: "itersmallest(heap)" and "iterlargest(heap)". Why: The functions nsmallest() and nlargest() are efficient (and sufficient) if n is known. However, if n is *not* known in advance, it would still be more efficient than sorting to run heapify() over a list and then have an iterator run heappop on each iteration. While this is easily implemented for min-heaps using heappop, max-heaps are not part of the Python-Implementation. Currently, they are only implemented in C. Possible counter-arguments: The straight-forward iterator implementation will manipulate the heap. This could be seen as a side-effect. It should, however, be enough to document that. Similar problems are documented for mutating sequences during iteration. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1158313&group_id=5470 _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com