The core of this recipe concerns the use of the
heapq module. The
heapq.heappop() insert and remove
items from a list
_queue in a way such that the first item in the
list has the smallest priority (as discussed in Recipe 1.4).
heappop() method always
returns the “smallest” item, so that is the key to making the queue pop
the correct items. Moreover, since the push and pop operations have
O(log N) complexity where N is the number of items in th...
Share this highlighthttp://www.safaribooksonline.com/a/python-cookbook-3rd/776/