Python 匿名函数、map()、reduce()、filter()

Python 匿名函数、map()、reduce()、filter()

匿名函数:简化函数定义

1、格式
lambda x,y :运算
Python 匿名函数、map()、reduce()、filter()
2、匿名函数作为参数
Python 匿名函数、map()、reduce()、filter()
Python 匿名函数、map()、reduce()、filter()
Python 匿名函数、map()、reduce()、filter()
3、map()

2个参数,1个是函数,1个是Iterable。
map将传入的参数依次作用到序列的每个元素,并把结果作为新的Iterator返回。
Python 匿名函数、map()、reduce()、filter()
Python 匿名函数、map()、reduce()、filter()

4、reduce()

Python 匿名函数、map()、reduce()、filter()

一次作用两个数 5和 3,做累积运算
Python 匿名函数、map()、reduce()、filter()
5、filter()
Python 匿名函数、map()、reduce()、filter()

Python 匿名函数、map()、reduce()、filter()