python实现获取序列中最小的几个元素
本文实例讲述了python实现获取序列中最小的几个元素。分享给大家供大家参考。 具体方法如下: 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
用户评论