PyNotes
261 subscribers
125 photos
7 videos
1 file
60 links
**Code is communication**
admin: @Xojarbu
https://t.me/solutions_py for problem solutions
Download Telegram
#heapq

Finding the Largest or Smallest N Items

The
heapq module has two functions—nlargest() and nsmallest()

✍️ note
that If you are simply trying to find the single smallest or largest item (N=1), it is faster to use min() and max()

source: "python cookbook" 3rd edition
#heapq
Title: heapq

The most important feature of a heap is that heap[0] is always the smallest item.

heapq.heappop()-pops off the first item and replaces it with the next smallest item (an operation that
requires O(log N) operations where N is the size of the heap)
source: Python cookbook