About 896,000 results
Open links in new tab
  1. 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 …

  2. In Python, heapq.heapify doesn't take cmp or key functions as …

    In Python, heapq.heapify doesn't take cmp or key functions as arguments like sorted does Asked 14 years, 2 months ago Modified 1 year, 2 months ago Viewed 66k times

  3. python - Removing an item from a priority queue - Stack Overflow

    Mar 30, 2011 · In Python, the heapq module provides a priority queue. It has methods for inserting and popping items. How do you remove an item that you have inserted that is not the lowest priority from …

  4. Python heapq vs. sorted complexity and performance

    Jul 10, 2014 · I'm relatively new to python (using v3.x syntax) and would appreciate notes regarding complexity and performance of heapq vs. sorted. I've already implemented a heapq based solution …

  5. python, heapq: difference between heappushpop() and heapreplace()

    43 I couldn't figure out the difference (other than ordinality of push/pop actions) between functions heapq.heappushpop () and heapq.heapreplace () when i tested out the following code.

  6. 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. Example:

  7. 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...

  8. 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 …

  9. What is the time complexity of heapq.nlargest? - Stack Overflow

    Nov 29, 2020 · For Heapq t largest or t smallest, the time complexity will be O(nlog(t)) Heapq will build the heap for the first t elements, then later on it will iterate over the remaining elements by pushing …

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

    174 According to the heapq documentation, the way to customize the heap order is to have each element on the heap to be a tuple, with the first tuple element being one that accepts normal Python …