摘要: 问题 我们想在某个集合中找出最大或最小的N个元素 解决方案 heapq模块中有两个函数nlargest()和nsmallest() import heapq nums = [1,8,2,23,7,-4,18,23,42,37,2] print(heapq.nlargest(3,nums)) # [4 阅读全文
posted @ 2022-05-16 18:21 我在路上回头看 阅读(213) 评论(0) 推荐(0)
摘要: 在函数内,yield语句可以作为表达式使用,出现在赋值运算符的右边,例如: def receiver(): print("Ready to receive") while True: n = (yield) print("go %s", n) 以这种方式使用yield语句的函数称为协程,向函数发送值 阅读全文
posted @ 2022-05-16 02:58 我在路上回头看 阅读(98) 评论(0) 推荐(0)