python中的zip与map和filter与reduce函数的区别
来源:互联网 发布:品牌 用户画像 大数据 编辑:程序博客网 时间:2024/06/05 18:22
filter与reduce函数的区别:
filter函数主要是针对已定义的函数和序列,传递单个对象,具有过滤作用
例如: def f(x):
if x>5:
return x
l=range(1,10)
filter(f,l)结果如下:[6,7,8,9]
而reduce函数主要也是针对已定义的函数和序列,不过传递时两个对象,并且可以经上次返回的结果作为下次传递的对象
例如,针对阶乘:
def f(x,y):
return x*y
l=range(5,10)
reduce(f,l)结果:15120
reduce(lambda x,y:x*y,range(5,10))结果同上
zip和map函数区别:
zip函数和map函数都是并行处理函数,zip处理方式比较单调而map函数处理相对比较丰富,
zip函数:zip(name,age,tel)
map函数:map(None,name,age,tel)
注意:map函数中None的位置为函数位置。
例如:
map函数与zip函数最主要的区别如下:
注释:str.capitalize()函数为使字符串首字母大写
str.replace()函数为替换 例如:是s.replace("name","yang",count=次数)
str.split()为分割函数
注意:图中出错的原因,这里替换的是字符一定要加单引号或双引号
0 0
- python中的zip与map和filter与reduce函数的区别
- python中的高阶函数map(),reduce(),filter()的区别
- Python中的map、zip、filter、reduce函数使用
- map,reduce,filter函数与python的list对象
- python常用函数(zip,map,filter,reduce)
- python的lambda、filter、map、reduce、zip函数
- python的filter,map,zip,reduce,apply
- Python的 enumerate zip map reduce filter
- python中map,filter和reduce函数区别
- python中的map、filter、reduce函数
- python中的map、filter、reduce函数
- python中的map、filter、reduce函数
- python中的map、filter、reduce函数
- python中的map、filter、reduce函数
- python中的map、filter、reduce函数
- python中的函数:filter/map/reduce/lambda
- python中的map、filter、reduce函数
- python中的map, filter, reduce函数
- hdu 1217 Arbitrage Floyd || SPFA
- VTK/ExamplesBoneyard/Cxx/PolyData/AddLineToPolydata
- 热备份mongodb
- 有效的数据库设计(降低表的相互关系)
- C语言函数返回多个值的方法
- python中的zip与map和filter与reduce函数的区别
- 学习资源一
- 深入浅出设计模式(四)
- 深入解析UUID及其应用
- submit与onsubmit
- js 取数组中最大最小值
- 项目ITP(四) javaweb http json 交互 in action (服务端 spring 手机端 提供各种工具类)勿喷!
- 运算符->重载
- C#杨辉三角