摘要: heapq 模块有两个函数:nlargest() 和 nsmallest() 可以完美解决这个问题。 import heapq nums = [1, 8, 2, 23, 7, -4, 18, 23, 42, 37, 2] print(heapq.nlargest(3, nums)) # Prints 阅读全文
posted @ 2019-06-14 20:16 C,python,linux,java 阅读(556) 评论(0) 推荐(0) 编辑