filter(F, L)

F: 函数。L:范围

filter的功能是:用函数F把L范围内的参数做过滤

通常和list一起使用,把过滤后的参数做成列表

list(filter(lambda n:not (n%3),range(0,100)))

表示的是找出0-100的整数中能被3整除的数

等同于:

[i for i in range(0,100) if not (i%3)]

>>> list(filter(lambda n:not(n%3),range(0,100)))
[0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60, 63, 66, 69, 72, 75, 78, 81, 84, 87, 90, 93, 96, 99]
>>> [i for i in range(0,100) if not(i%3)]
[0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60, 63, 66, 69, 72, 75, 78, 81, 84, 87, 90, 93, 96, 99]
>>>

Python 3.5 filter的更多相关文章

  1. paip. uapi 过滤器的java php python 实现aop filter

    paip. uapi 过滤器的java php python 实现aop filter filter 是面向切面编程AOP.. 作者Attilax  艾龙,  EMAIL:1466519819@qq. ...

  2. python中的filter、map、reduce、apply用法

    1. filter 功能: filter的功能是过滤掉序列中不符合函数条件的元素,当序列中要删减的元素可以用某些函数描述时,就应该想起filter函数. 调用: filter(function,seq ...

  3. Python高级教程-filter

    Python中的filter() Python内建的filter()函数用于过滤序列.和map()类似,filter()也接收一个函数和一个序列.和map()不同的是,filter()把传入的函数依次 ...

  4. Python特殊语法--filter、map、reduce、lambda

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

  5. Python中Lambda, filter, reduce and map 的区别

    Lambda, filter, reduce and map Lambda Operator Some like it, others hate it and many are afraid of t ...

  6. Python 3. 里filter与generator expression的区别

    # -*- coding: utf-8 -*- """ A test to show the difference between filter and genrator ...

  7. python map, reduce,filter 使用

    参考python built-on function: http://docs.python.org/2.7/library/functions.html?highlight=map%20reduce ...

  8. Python自学笔记-filter()函数(来自廖雪峰的官网Python3)

    感觉廖雪峰的官网http://www.liaoxuefeng.com/里面的教程不错,所以学习一下,把需要复习的摘抄一下. 以下内容主要为了自己复习用,详细内容请登录廖雪峰的官网查看. Python内 ...

  9. python库函数Map, Filter and Reduce的用法

    python中有三个函数式编程极大的简化了程序的复杂性,这里就做一下讨论和记录. 一 Map:应用在链表输入所有元素的函数,它的格式如下所示: map(function_to_apply, list_ ...

  10. Python中的filter()函数的用法

    转载自:脚本之家 Python内建的filter()函数用于过滤序列. 和map()类似,filter()也接收一个函数和一个序列.和map()不同的时,filter()把传入的函数依次作用于每个元素 ...

随机推荐

  1. 发送邮件,出现异常:服务器响应为: Error: need EHLO and AUTH first !"

    在使用 System.Net.Mail组建发送邮件的时候出现了"命令顺序不正确. 服务器响应为: Error: need EHLO and AUTH first !"异常 解决方法 ...

  2. js操作ListBox列表(select)内移动

    <script> function listBoxClick(obj, addName) { var $objSelected = $(obj).find("option:sel ...

  3. mysql:The user specified as a definer ('xxx'@'%') does not exist 解决方法

    发生这种问题.大概率是用户不存在或者是权限不够 用户不存在.用可视化工具新建一个. 权限不够 ,运行下面命令: 如:我的错误: The user specified as a definer ('mo ...

  4. 【2】学习C++之引用

    C++中的引用类似于现实生活中人们之间起昵称,昵称和本名都可以辨别人. 1.普通变量的引用: ;//a为本名 int &b=a;//b为a的昵称 其中不能光有昵称没有本名,如果只定义了引用,却 ...

  5. selenium+webservice进行百度登录

    from selenium import webdriverimport time driver = webdriver.Chrome()driver.get("https://www.ba ...

  6. 关于ViewPager+Fragment中的坑

    1.我的情况是Activity里嵌套了Fragment_0,然后Fragment_0里面又嵌套了两个Fragment:Fragment_1.Fragment_2,然后我在其中一个Fragment,Fr ...

  7. codeforces 1151 D

    SM的水题. codeforces 1151D 当时写对了,因为第一题卡了,,然后这题就没细想,原来是没开longlong. 题意:n个位置每个位置有a和b,让sum=(每个点的左面的点的数量*a+右 ...

  8. Linux中Too many open files

    1.ulimit –a open files一项就是默认的句柄数,最大为 65536 2.修改最大open files /etc/security/limits.conf文件中,加入以下配置: * s ...

  9. [Linux]出错处理errno

    概述 公共头文件<errno.h>定义了一个整型值errno以及可以赋予它的各种常量. 大部分函数出错后返回-1,并且自动给errno赋予当前发生的错误枚举值. 需要注意的一点是,errn ...

  10. C# 最全的文件工具类FileHelper

    using System; using System.Collections.Generic; using System.Data; using System.IO; using System.Lin ...