为什么lambda_var的值在变化?

时间:2017-04-14 16:21:17

标签: python python-2.7 python-3.x lambda pycharm

# sieve of Eratosthenes? trial division? , python 3.6, pycharm 2017.1
def _odd_iter():
    n = 1
    while True:
        n += 2
        yield n


def primes():
    yield 2
    it = _odd_iter()
    while True:
        num = next(it)
        yield num
        abc = num
        f_inner = lambda lambda_var: lambda x: x % lambda_var > 0 # lambd_var here
        f_outter = f_inner(abc)
        it = filter(f_outter, it)

i = 0
for nx1 in primes():
    i += 1
    if i <= 100:
        print(i, nx1, sep="#\t")
    else:
        break

当我试图观察“lambda_var”的值并将断点设置为它的行时,我发现它在每个循环中从最小值到最大值进行转换,而且我认为这不太正常。 只是想知道,为什么?

例如:逐步:

steps   num abc lambda_var
1   3   3   undef
2   undef   undef   3
3   5   5   undef
4   undef   undef   5
5   undef   undef   3
6   undef   undef   5
7   7   7   undef
8   undef   undef   7
9   undef   undef   3
10  undef   undef   5
11  undef   undef   7
12  11  11  undef
13  undef   undef   11
14  undef   undef   3
15  undef   undef   5
16  undef   undef   7
17  undef   undef   11
18  13  13  undef
19  undef   undef   13
20  undef   undef   3
21  undef   undef   5
22  undef   undef   7
23  undef   undef   11
24  undef   undef   13

0 个答案:

没有答案