Skip to content

Instantly share code, notes, and snippets.

@wanderindev
Created June 19, 2022 03:03
Show Gist options
  • Select an option

  • Save wanderindev/438ac8ea947a10bf33c2c3b3f804ea91 to your computer and use it in GitHub Desktop.

Select an option

Save wanderindev/438ac8ea947a10bf33c2c3b3f804ea91 to your computer and use it in GitHub Desktop.
def pull(self) -> Union[str, None]:
"""
Return and remove the task with the highest priority.
Since Python's heapq is implemented as a min heap, a
smaller number mean the higher priority, i.e. priority 1
has a higher priority that priority 2.
Elements with same priority are pulled in the order of
insertion.
"""
if self.is_empty():
return None
return heapq.heappop(self.pqueue)[2]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment