Python生成器常见问题及解决方案

qftomny 10 0 PDF 2020-12-23 02:12:06

在Python中,生成器和函数很像,都是在运行的过程中才会去确定各种变量的值,所以在很多情况下,会导致各种各样的问题。 def generator_test1(): # 0...9 generator x = (i for i in range(10)) # 5..9 generator x_filter = filter(lambda y: y >= 5, x) # first use the x L = list(x) print("L, x", L) # then use x_filter l = list(x_filter) print("l,

用户评论
请输入评论内容
评分:
暂无评论