RosettaCodeData/Task/Priority-queue/Python/priority-queue-3.py

14 lines
317 B
Python
Raw Permalink Normal View History

2013-04-10 23:57:08 -07:00
>>> from heapq import heappush, heappop, heapify
>>> items = [(3, "Clear drains"), (4, "Feed cat"), (5, "Make tea"), (1, "Solve RC tasks"), (2, "Tax return")]
>>> heapify(items)
>>> while items:
2014-01-17 05:32:22 +00:00
print(heappop(items))
2013-04-10 23:57:08 -07:00
(1, 'Solve RC tasks')
(2, 'Tax return')
(3, 'Clear drains')
(4, 'Feed cat')
(5, 'Make tea')
>>>