filter built-in function

filter(f,sequence)

filter can apply the function f to each element of sequence. If return is true the element will be returned and re-organized to be a new sequence. The type of new sequence can be list/tuple/string, this depends on the input sequence type.

>>> l=[1,2,3,4,5]
>>> f = lambda x: True if x%2 == 0 else False
>>> filter(f,l)
[2, 4]
>>> t=(1,2,3,4,5)
>>> filter(f,t)
(2, 4)

map built-in function

map(f, sequence)

map will apply f to each element of sequence. The result will be returned to be a new list(Unless filter, the return will always a list).

>>> f= lambda y : y*2
>>> l=[1,2,3]
>>> t=(1,2,3)
>>> map(f,l)
[2, 4, 6]
>>> map(f,t)
[2, 4, 6]

reduce() built-in function

reduce(f, sequence, start_value)

reduce apply f to sequence by the order of the sequence. If there is a start_value, this one will be called first.

>>> l = [1,2,3,4,5,6,7,8,9]
>>> f = lambda x,y : x+y
>>> reduce(f,l)
45
>>> reduce(f,l, 20)
65

python: filter, map, reduce, lambda的更多相关文章

  1. filter,map,reduce,lambda(python3)

    1.filter filter(function,sequence) 对sequence中的item依次执行function(item),将执行的结果为True(符合函数判断)的item组成一个lis ...

  2. Python2.7学习笔记-定义函数、filter/map/reduce/lambda

    我把写的代码直接贴在下面了,注释的不是很仔细,主要是为了自己复习时方便查找,并不适合没有接触过python的人看,其实我也是初学者. #定义函数 def my_abs(x): if x>=0: ...

  3. python filter map reduce

    filter(function, iterable): Construct a list from those elements of iterable for which function retu ...

  4. Python中特殊函数和表达式 filter,map,reduce,lambda

    1. filter 官方解释:filter(function or None, sequence) -> list, tuple, or string Return those items of ...

  5. Python中 filter | map | reduce | lambda的用法

      1.filter(function, sequence):对sequence中的item依次执行function(item),将执行结果为True的item组成一个List/String/Tupl ...

  6. Python学习(五)函数 —— 内置函数 lambda filter map reduce

    Python 内置函数 lambda.filter.map.reduce Python 内置了一些比较特殊且实用的函数,使用这些能使你的代码简洁而易读. 下面对 Python 的 lambda.fil ...

  7. Python经常使用内置函数介绍【filter,map,reduce,apply,zip】

    Python是一门非常简洁,非常优雅的语言,其非常多内置函数结合起来使用,能够使用非常少的代码来实现非常多复杂的功能,假设相同的功能要让C/C++/Java来实现的话,可能会头大,事实上Python是 ...

  8. Python内置函数之filter map reduce

    Python内置函数之filter map reduce 2013-06-04 Posted by yeho Python内置了一些非常有趣.有用的函数,如:filter.map.reduce,都是对 ...

  9. Python之匿名函数(filter,map,reduce)

    参考博客:Python匿名函数详解--http://blog.csdn.net/csdnstudent/article/details/40112803 Python内建函数之——filter,map ...

随机推荐

  1. 阿里云CDN服务功能介绍

  2. InChatter系统开源聊天模块前奏曲

    最近在研究WCF,又因为工作中的项目需要,要为现有的系统增加一个聊天模块以及系统消息提醒等,因此就使用WCF做服务器端开发了一个简单的系统. 开发最初学习了东邪孤独大哥的<传说的WCF系列> ...

  3. 理清楚HTML和DHTML和XML的概念

    DHTML 不是 W3C 标准DHTML 指动态 HTML(Dynamic HTML).DHTML 不是由万维网联盟(W3C)规定的标准.DHTML 是一个营销术语 - 被网景公司(Netscape) ...

  4. table鼠标滑过变颜色

    table鼠标滑过变颜色 添加 table tr:hover{background-color: #eee;} 设置鼠标滑过行背景变色,重新刷新浏览器页面.  一般设置灰色,eee

  5. git的使用 及一些常见的错误处理

    git安装使用 添加文件到Git仓库,分两步: 1.使用命令git add <file>,注意,可反复多次使用,添加多个文件: 2.使用命令git commit -m <messag ...

  6. group by 和 聚合函数的使用

    有这样一个表数据: 学生姓名,学生手机号,上课日期,上课科目 科目分: 语文.数学.英语.计算机 要求统计一个这样子的结果: 学生姓名,学生手机号,第一次上课日期,迄今一共上了多少节课,上的最多的科目 ...

  7. 【C语言】控制台窗口图形界面编程(一)句柄和文本属性

    目录 00. 目录 01. 句柄 02. GetStdHandle函数 03. CloseHandle函数 04. SetConsoleTextAttribute函数 05. 十进制颜色对照表 06. ...

  8. Android-ViewPagerIndicator框架使用——CirclePageIndicator

    前言:Circle适用于应用新功能的展示页和商品的多张图片的展示功能. 1.定义布局文件:SampleCirclesDefault中添加了一个布局:simple_circles. 布局中定义一个Lin ...

  9. wampsever修改数据库密码

    ①进入localhost中的mysql数据库 ②再进入mysql数据库中的user表 ③将user表中的三个root账号的密码全部改为你想要的密码(不需要经过MD5加密) ④保存后重新启动服务 如果在 ...

  10. Spring中操作日志记录web请求的body报文

    在spring中,通常可以使用切面编程方式对web请求记录操作日志.但是这种方式存在一个问题,那就是只能记录url中的请求参数,无法记录POST或者PUT请求的报文体,因为报文体是放在request对 ...