Skip to content

Instantly share code, notes, and snippets.

@pn11
Created September 16, 2019 02:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pn11/aac52d40bcfc24a1b000f121619a3d21 to your computer and use it in GitHub Desktop.
Save pn11/aac52d40bcfc24a1b000f121619a3d21 to your computer and use it in GitHub Desktop.
Priority queue
import heapq as hq
que = []
hq.heappush(que, (1, "TEST1"))
hq.heappush(que, (0, "TEST0"))
hq.heappush(que, (2, "TEST2"))
print(que)
priority, a = hq.heappop(que)
print(priority, a)
print(que)
priority, a = hq.heappop(que)
print(priority, a)
print(que)
priority, a = hq.heappop(que)
print(priority, a)
@pn11
Copy link
Author

pn11 commented Sep 16, 2019

Output

[(0, 'TEST0'), (1, 'TEST1'), (2, 'TEST2')]
0 TEST0
[(1, 'TEST1'), (2, 'TEST2')]
1 TEST1
[(2, 'TEST2')]
2 TEST2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment