Map Filter和Reduce函数
来源:互联网 发布:小海家淘宝 编辑:程序博客网 时间:2024/06/05 05:30
Map Filter和Reduce函数
Map函数
map中文意思是映射,和数学中的集合映射是一样的
a = [1,2,3,4,5] #集合adef f (x): #映射规则f(x) return x*xb = map(f, a) #每一个x属于a 经过映射规则产生b集合,b集合是a集合的一个满射(python3返回的是一个迭代器)print(list(b))'''结果:[1, 4, 9, 16, 25]'''
Filter函数
filter意思是过滤器,过滤掉不需要的留下需要的。
a = [1,2,3,4,5 ] #集合adef f(x): #映射规则f(x) ->[true,false] 相当于f(x)和Filter的复合映射,if f(x)== true: return x return x>3b = filter(f, a) #留下f(x)=true 的xprint(list(b))'''结果:[4, 5]'''
Reduce函数
Reduce的含义有减少;缩小;归纳为,这我我觉得它的意思倾向于归纳。
from functools import reduce #需要引入reducea = [1,2,3,4,5]def f( a, b ): print(a,b) return a+b;b = reduce( f, a )print(b)'''结果:1 23 36 410 515从结果可以看出 如果a为一个数列[a0,a1,a2,...,an]a前n项和为S[n] = S[n-1] + anf就是用来数列求和的作用,S[n] = f(S[n-1],an)'''
2 0
- Map Filter和Reduce函数
- map、filter、reduce函数
- 高阶函数:Filter、Map和Reduce
- Map,Filter和Reduce
- Map,Filter 和 Reduce
- Map,Filter 和 Reduce
- Python3.4中filter函数,map函数和reduce函数
- Python3.4中filter函数,map函数和reduce函数
- Python3.4中filter函数,map函数和reduce函数
- map、reduce、filter内置函数
- swift map filter reduce函数
- python map函数,filter,reduce
- python map, reduce, filter 函数
- filter,map,reduce,apply函数
- Python 函数式编程之 filter()、map()和reduce()
- 链表内置函数 filter(), map(), 和 reduce()
- python中map,filter和reduce函数区别
- Python 中 map,reduce,和filter 内置函数的方法
- 吉祥坊WellBET成为意甲官方赞助商造假
- Java ConcurrentModificationException异常原因和解决方法
- RabbitMQ安装遇到的问题(转载)
- Volley使用
- bluestore调研
- Map Filter和Reduce函数
- Linux环境下修改MySQL端口方法
- bzoj3930
- web网络知识1
- 【Eclipse中的 Git插件使用】简单操作
- SSM框架 之 Spring-AOP(面向切面编程)
- PAT 乙级 1003. 我要通过!(20) Java版
- C++类的继承中构造函数和析构函数调用顺序例子
- 【安装eclipse, 配置java环境教程】 编写第一个java程序