6
阵列
为python heap implementation的使用一个简单的例子是定义堆键元组
>>> from heapq import heappush, heappop
>>> heap = []
>>> data = [1, 3, 5, 7, 9, 2, 4, 6, 8, 0]
>>> for item in data:
heappush(heap, item)
在更复杂的情形中,我有元组的像
tuples = [(5,"foo",True),(2,"bar", False),(8,"foobar",True)]
阵列,并希望使用每个元组的第一个条目作为堆键,即元组应该根据堆中的数字排序。
我该怎么做?