map,reduce,filter函数与python的list对象
来源:互联网 发布:unity3d真实地形制作 编辑:程序博客网 时间:2024/05/18 09:06
这里要介绍的map, reduce和filter函数是Python语言内置的函数,与MapReduce模式没有任何关系,这三个函数作用于Python的List对象。
filter函数从list对象中选出符合条件的元素,返回一个新的list,比如:
>>> filter(lambda x: x%2!=0 and x%3!=0, range(2,25))[5, 7, 11, 13, 17, 19, 23]上面这个例子从2, 3, 4 ...24中选出不能被2和3整除的数字。
map函数对列表中每一个元素执行函数调用(即第一个参数指定的函数),然后返回结果的列表:
>>> map(lambda x: x*x*x, range(1,11))[1, 8, 27, 64, 125, 216, 343, 512, 729, 1000]>>>
这个例子对1,2,3...10每个元素计算立方并返回。
reduce函数对列表中的元素进行二目运算,先是第一个元素和第二个元素运算(做什么运算由函数参数指定),然后把结果和第三个元素运算,以此类推
>>> def add(x,y): return x+y>>> reduce(add, range(1,11))55把列表1,2,3...10都加起来,并返回一个结果。
0 0
- map,reduce,filter函数与python的list对象
- Python的map、filter、reduce函数
- Python的map、filter、reduce函数
- Python的map、filter、reduce函数
- python的map,filter,reduce函数
- python map函数,filter,reduce
- python map, reduce, filter 函数
- python的 filter, map, reduce, lambda, list comprehension
- python-map()函数,reduce()函数,filter()函数
- python map函数,Filter函数,Reduce函数
- python中的zip与map和filter与reduce函数的区别
- python的几个内建函数:apply(),filter(),map(),reduce()
- python的几个内建函数:apply(),filter(),map(),reduce()
- python的几个内建函数:apply(),filter(),map(),reduce(
- python的几个内建函数:apply,filter,map,reduce
- python的几个内建函数:apply(),filter(),map(),reduce()
- python的lambda表达式 内建函数filter map reduce
- python 的 map(),reduce(),filter(),返回函数,闭包
- VC _T和L
- CodeForces 378A Playing with Dice(水题)
- 获取客户端ip地址方法和通过curl在命令行提交post数据到服务器
- 十七.交通灯管理系统
- CodeForces 378B Semifinals(贪心)
- map,reduce,filter函数与python的list对象
- vs2010 编译 duilib v391 报错的问题
- 今天开通了博客,加油!
- FreeRTOS 源代码的编程标准与命名约定
- hdu 2955 Robberies
- Lua Metatable
- ASP.NET基础(一)
- 统一资源管理与调度平台(系统)介绍
- 萬惡WITH為首之Javascript