在python2和python3中filter是不同的,其中在python2中filter返回的是一个list,可以直接使用

>>> a = [1,2,3,4,5,6,7]
>>> filter(lambda x: x%2==0, a)
[2, 4, 6]

而在python3中,返回的是<filter object at 0x05D25D90>,应将filter转换成list,才能继续使用

>>> list(filter(lambda x:x*2, a))
[1, 2, 3, 4, 5]

python2和python3中filter函数的更多相关文章

  1. 有关python2与python3中关于除的不同

    有关python2与python3中关于除的不同 python中2版本与3版本关于除的处理还是有一些差异的. 在python 2.7.15中除(/)是向下取整的,即去尾法. 123/10 # 结果 1 ...

  2. Python2和Python3中urllib库中urlencode的使用注意事项

    前言 在Python中,我们通常使用urllib中的urlencode方法将字典编码,用于提交数据给url等操作,但是在Python2和Python3中urllib模块中所提供的urlencode的包 ...

  3. python2和python3中range的区别

    参考自 python2和python3中的range区别 - CSDN博客 http://blog.csdn.net/xiexingshishu/article/details/48581379 py ...

  4. python中filter函数

    python中filter()函数   filter()函数是 Python 内置的另一个有用的高阶函数,filter()函数接收一个函数 f 和一个list,这个函数 f 的作用是对每个元素进行判断 ...

  5. Python2和Python3中列表推导式的不同

    Python2和Python3中列表推导式的不同 python2 >>> x = 'my girl' >>> lst = [x for x in 'hello'] ...

  6. [Python3 填坑] 012 字典的遍历在 Python2 与 Python3 中区别

    目录 1. print( 坑的信息 ) 2. 开始填坑 2.1 Python2 中字典的遍历 2.2 Python3 中字典的遍历 2.3 结论 1. print( 坑的信息 ) 挖坑时间:2019/ ...

  7. Python2和Python3中的rang()不同之点

    知道在python中rang()是一个有序的列表,在使用过程发现,Python2和Python3中的rang()不同之点,下面讲述不同之点 1,Python2 rang()用法 ->> r ...

  8. 用python实现矩阵转置,python3 中zip()函数

    前几天群里有同学提出了一个问题:手头现在有个列表,列表里面两个元素,比如[1, 2],之后不断的添加新的列表,往原来相应位置添加.例如添加[3, 4]使原列表扩充为[[1, 3], [2, 4]],再 ...

  9. Python2和Python3中print的不同点

    在Python2和Python3中都提供print()方法来打印信息,但两个版本间的print稍微有差异 主要体现在以下几个方面: 1.python3中print是一个内置函数,有多个参数,而pyth ...

随机推荐

  1. 设置eclipse的Maven插件引入依赖jar包后自动下载并关联相应的源码(转)

    好多用 Maven 的时候会遇到这样一个棘手的问题: 就是添加依赖后由于没有下载并关联源码,导致自动提示无法出现正确的方法名,而且不安装反编译器的情况下不能进入方法内部看具体实现 . 其实 eclip ...

  2. VS2015 调试出现无法启动iis express web服务器

    VS2015 调试出现无法启动iis express web服务器 在项目目录下找到.vs文件夹,然后在.vs/config/applicationhost.config找到这个配置文件,删除掉,然后 ...

  3. 牛客网36-A,B题解

    A.Rabbit的字符串 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536K 64bit IO Format: %lld 题目描述 Rabbit得到了一 ...

  4. How far away(DFS+vector存图)

    There are n houses in the village and some bidirectional roads connecting them. Every day peole alwa ...

  5. hdu4403- A very hard Aoshu problem(搜索)

    枚举等号的位置,然后暴力搜索一波 这个题本身不难,但它是我第一次使用对拍程序来查找错误,值得纪念. #include<cstdio> #include<string.h> #i ...

  6. Auto yes to the License Agreement on sudo apt-get -y install oracle-java7-installer

    参考一 参考二 我自己的做法是: && add-apt-repository ppa:webupd8team/java \ && apt-get update \ &a ...

  7. Spring Cloud 熔断器

    目录 Spring Cloud 熔断器 Hystrix ribbon中使用hystrix feign中使用hystrix Spring Cloud 熔断器 在微服务架构中,根据业务来拆分成一个个的服务 ...

  8. 自动生成sql

    添加下面这个类 public static class GetAllAttribute<T> where T : class { public static string Names; p ...

  9. c# ExpandoObject动态扩展对象

    js中的Object 对象. php中的stdClass. c# 也有动态可扩展对象 ExpandoObject,需要添加System.Dynamic引用 用法: dynamic model = ne ...

  10. CSS中垂直水平居中

    方法一:使用flex布局,父级元素设置justify-content和align-items <div class="cont"> <div class=&quo ...