Discuss / Python / 关于filter()函数求素数的问题

关于filter()函数求素数的问题

def _not_divisible(n):
    return lambda x: x % n > 0

def primes():
    yield 2
    it = _odd_iter() # 初始序列
    while True:
        n = next(it) # 返回序列的第一个数
        yield n
        it = filter(_not_divisible(n), it) # 构造新序列

_not_divisible(n)函数只接收了n,x的值又是怎么传入的


  • 1

Reply