"""lambda 参数列表 : 返回值lambda 参数形式: 1.无参数:lambda:100 2.一个参数:lambda a: a 3.默认参数:lambda a, b, c=100: a + b + c 4.可变参数:*args,返回元组 lambda *args: args 5.可变参数:*kwargs,返回字典 lambda **kwargs: kwargs lambda 应用:简化代码 1.判断,lambda a, b: a if a > b else b…
# if we need it only once and it's quite simple def make_incrementor(n): return lambda x: x + n f = make_incrementor(2) print f(3) # filter, map, reduce foo = [2, 18, 9, 22, 17, 24, 8, 12, 27] print filter(lambda x: x % 3 == 0, foo) print map(lambda…