python学习数据结构heapq
>>> import heapq
>>> nums = [1, 8, 2, 23, 7, -4, 18, 23, 42, 37, 2]
>>> print(heapq.nlargest(3, nums)) # Prints [42, 37, 23]
[42, 37, 23]
>>> print(heapq.nsmallest(3, nums)) # Prints [-4, 1, 2]
[
原创
2017-12-28 17:05:57 ·
152 阅读 ·
0 评论