我将lambda函数写在外部函数里能正常筛选,但是如果直接写在filter函数里就不起作用。运行结果:运行结果:代码如下:def get_numbers(): n = 1 while True: n += 2 yield ndef is_divisible(num): return lambda x: x % num > 0def primes(): yield 2 temp = get_numbers() while True: num = next(temp) yield num temp = filter(is_divisible(num), temp)for i in primes(): if i < 100: print(i, end = ' ') else: break
添加回答
举报
0/150
提交
取消