具体方法如下:
import heapq import random def issorted(data): data = list(data) heapq.heapify(data) while data: yield heapq.heappop(data) alist = [x for x in range(10)] random.shuffle(alist) print 'the origin list is',alist print 'the min in the list is' for x in issorted(alist): print x,程序运行结果如下:
此外还有一个更为简单的方法: