Lambda+递归

lambda:

def is_odd(n):
    return n % 2 == 1

L = list(filter(is_odd, range(1, 20)))
print(L)

print(list(filter(lambda n: n % 2 == 1, range(1, 20))))

递归:

def fact(n):
    if n == 1:
        return n
    else:
        return fact(n-1) + n

print(fact(100))

#fact(3) = fact(2) + 3 = fact(1) + 2 + 3

你可能感兴趣的:(Lambda+递归)