python filter map reduce
Construct a list from those elements of iterable for which function returns true.
-
Apply function to every item of iterable and return a list of the results. If additional iterable arguments are passed, function must take that many arguments and is applied to the items from all iterables in parallel.
Apply function of two arguments cumulatively to the items of iterable, from left to right, so as to reduce the iterable to a single value
# -*- coding: utf-8 -*-
def test():
lst = [[1,2,3], [5], [5, 6]]
print ' ---- use filter ----'
ret = []
print filter(lambda e: ret.extend(e), lst)
print ret print ' ---- use map ----'
ret = []
print map(lambda e: ret.extend(e), lst)
print ret print ' ---- use reduce ----'
ret = reduce(lambda r, e: r.extend(e) or r, lst, [])
print ret print ' ---- use itertools.chain ----'
import itertools
print list(itertools.chain(*lst)) if __name__ == '__main__':
test()
最后,只要可以,尽量使用list comprehension。
python filter map reduce的更多相关文章
- python: filter, map, reduce, lambda
filter built-in function filter(f,sequence) filter can apply the function f to each element of seque ...
- Python学习(五)函数 —— 内置函数 lambda filter map reduce
Python 内置函数 lambda.filter.map.reduce Python 内置了一些比较特殊且实用的函数,使用这些能使你的代码简洁而易读. 下面对 Python 的 lambda.fil ...
- Python之匿名函数(filter,map,reduce)
参考博客:Python匿名函数详解--http://blog.csdn.net/csdnstudent/article/details/40112803 Python内建函数之——filter,map ...
- Python: lambda, map, reduce, filter
在学习python的过程中,lambda的语法时常会使人感到困惑,lambda是什么,为什么要使用lambda,是不是必须使用lambda? 下面就上面的问题进行一下解答. 1.lambda是什么? ...
- Python经常使用内置函数介绍【filter,map,reduce,apply,zip】
Python是一门非常简洁,非常优雅的语言,其非常多内置函数结合起来使用,能够使用非常少的代码来实现非常多复杂的功能,假设相同的功能要让C/C++/Java来实现的话,可能会头大,事实上Python是 ...
- Python内置函数之filter map reduce
Python内置函数之filter map reduce 2013-06-04 Posted by yeho Python内置了一些非常有趣.有用的函数,如:filter.map.reduce,都是对 ...
- filter,map,reduce,lambda(python3)
1.filter filter(function,sequence) 对sequence中的item依次执行function(item),将执行的结果为True(符合函数判断)的item组成一个lis ...
- Python2.7学习笔记-定义函数、filter/map/reduce/lambda
我把写的代码直接贴在下面了,注释的不是很仔细,主要是为了自己复习时方便查找,并不适合没有接触过python的人看,其实我也是初学者. #定义函数 def my_abs(x): if x>=0: ...
- python基础——map/reduce
python基础——map/reduce Python内建了map()和reduce()函数. 如果你读过Google的那篇大名鼎鼎的论文“MapReduce: Simplified Data Pro ...
随机推荐
- Nodejs mongodb 管理组件adminmongodb
强大的 nodejs的mongodb管理工具,强大到即下即用: 安装需求: 1.git命令获取组件包,git clone https://github.com/mrvautin/adminMongo. ...
- 表字符集latin1,client如何查看中文字符
表结构如下: . row *************************** Table: my_data_7e Create Table: CREATE TABLE `my_data_7e` ( ...
- 【机器学习】人工神经网络ANN
神经网络是从生物领域自然的鬼斧神工中学习智慧的一种应用.人工神经网络(ANN)的发展经历的了几次高潮低谷,如今,随着数据爆发.硬件计算能力暴增.深度学习算法的优化,我们迎来了又一次的ANN雄起时代,以 ...
- linux 运维常用工具表
https://code.google.com/p/httperf/ ※测量Web服务器的性能 ./configure make &&make install http://ww ...
- prometheus client_golang使用
序言 Prometheus是一个开源的监控系统,拥有许多Advanced Feature,他会定期用HTTP协议来pull所监控系统状态进行数据收集,在加上timestamp等数据组织成time se ...
- 开源巨献:Google最热门60款开源项目
文章整理于互联网.本文收集了 60款 Google 开源的项目,排名顺序按照 Github ★Star 数量排列. 0.机器学习系统 TensorFlow ★Star 62533 TensorFlo ...
- smartClient 1--框架介绍
一.是什么(以下简称SC) smartClient 是一个基于web技术的开发框架,主要包括: 一个无需安装的 Ajax/HTML5 客户端引擎 UI组件和服务(采用富客户端RIA)--- 提 ...
- Docker 三剑客之 Docker Swarm
上一篇:Docker 三剑客之 Docker Compose 阅读目录: Docker Machine 创建 Docker 主机 Docker Swarm 配置集群节点 Docker Service ...
- C语言结构体1.1
结构体组成 struct 结构体名: 类型名 成员名: 建立结构体 结构体名 类型名 { 成员: }: 建立一个关于学生信息的结构体(名字,年龄,性别,学号,成绩): 结构体定义 //结构体声明 s ...
- hdu 1496 Equations hash表
hdu 1496 Equations hash表 题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1496 思路: hash表,将原来\(n^{4}\)降 ...