Skip to content

Instantly share code, notes, and snippets.

@tomislater
Created October 6, 2013 16:51
Show Gist options
  • Select an option

  • Save tomislater/6856311 to your computer and use it in GitHub Desktop.

Select an option

Save tomislater/6856311 to your computer and use it in GitHub Desktop.
>>> import heapq
>>> from random import randint
>>> my_heap = []
>>> for _ in xrange(20):
>>> heapq.heappush(my_heap, randint(0, 3000))
>>> print my_heap
[134, 541, 156, 895, 706, 1700, 427, 2049, 1108, 1092, 1895, 2807, 2469, 811, 717, 2962, 2992, 2356, 1935, 2834]
>>> print heapq.heappop(my_heap)
134
>>> print heapq.heappop(my_heap)
156
>>> print heapq.heappop(my_heap)
427
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment