About 53 results
Open links in new tab
  1. Understanding how to create a heap in Python - Stack Overflow

    Oct 5, 2012 · In Python 2.X and 3.x, heaps are supported through an importable library, heapq. It supplies numerous functions to work with the heap data structure modelled in a Python list.

  2. What is Python's heapq module? - Stack Overflow

    The heapq module maintains the heap invariant, which is not the same thing as maintaining the actual list object in sorted order. Quoting from the heapq documentation: Heaps are binary trees for which …

  3. What do I use for a max-heap implementation in Python?

    Python includes the heapq module for min-heaps, but I need a max-heap. What should I use for a max-heap implementation in Python?

  4. python - How to make heapq evaluate the heap off of a specific ...

    Oct 17, 2010 · I wish to hold a heap of objects, not just numbers. They will have an integer attribute in them that the heap can sort by. The easiest way to use heaps in python is heapq, but how do I tell it to...

  5. How to maintain dictionary in a heap in python? - Stack Overflow

    Feb 10, 2013 · How to maintain dictionary in a heap in python? Ask Question Asked 13 years, 2 months ago Modified 5 years, 11 months ago

  6. Peeking in a heap in python - Stack Overflow

    May 3, 2011 · What is the official way of peeking in a python heap as created by the heapq libs? Right now I have def heappeak (heap): smallest = heappop (heap) heappush (heap, smallest) return …

  7. python - How to iterate heapq without losing data? - Stack Overflow

    Jan 24, 2020 · Is there a way to iterate heapq such that I get the values in sorted order without mutating heapq/losing data? If not, how can I efficiently imitate the desired behavior? The solution I came up …

  8. object - min heap in python - Stack Overflow

    Mar 24, 2009 · I'd like to store a set of objects in a min heap by defining a custom comparison function. I see there is a heapq module available as part of the python distribution. Is there a way to use a custom

  9. python - heapq with custom compare predicate - Stack Overflow

    The heapq documentation suggests that heap elements could be tuples in which the first element is the priority and defines the sort order. More pertinent to your question, however, is that the …

  10. Python: delete element from heap - Stack Overflow

    Apr 15, 2012 · Python has heapq module which implements heap data structure and it supports some basic operations (push, pop). How to remove i-th element from the heap in O(log n)? Is it even …