About 3,320,000 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 …

  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, …

  5. 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) …

  6. Python: Update value of element in heapq - Stack Overflow

    Aug 15, 2014 · How can I make such update? The basic steps for updating elements in the heap following the above logic would be: Check dictionary to get the index of the element you want …

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

    Feb 10, 2013 · How to maintain dictionary in a heap in python? Asked 12 years, 10 months ago Modified 5 years, 7 months ago Viewed 36k times

  8. algorithm - Search an element in a heap - Stack Overflow

    In python it can be done with the help of a dictionary. update the index of the node in the dictionary every time you perform an operation in the min heap. You should only implement …

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

    import heapq heap = [] heapq.heapify(heap) for element in a: heapq.heappush(heap, (element[1],element[0])) This is a simple trick if this does your job and you don't want to get …

  10. Maintain a fixed size heap -python - Stack Overflow

    I want to maintain a fixed heap size of say 3,so when I next have heapq.heappush(h,(3,15)),key with value 20 gets deleted and I am left with values 3,5 and 10.Any ideas how?