注意:结果取完一次就没了:

# -*- coding:utf-8 -*-


### functools.reduce

from functools import reduce r1 = reduce(lambda x,y:x+y,[1,2,3,4,5])
print(r1) #
r2 = reduce(lambda x,y:x*y,[1,2,3,4,5])
print(r2) # ### map
r3 = map(lambda x:x**2,[1,2,3])
print(r3,list(r3)) # <map object at 0x00000155BC0EBC50> [1, 4, 9]
print(list(r3)) # [] —— 取完一次就没得了! ### zip
r4 = zip((1,2,3),("wanghw","naruto","sasuke"))
print(r4,dict(r4)) # <zip object at 0x00000155BC0FAC88> {1: 'wanghw', 2: 'naruto', 3: 'sasuke'}
print(dict(r4)) # {} —— 取完一次就有没得了!
r5 = zip((4,5,6),("whw","naroo","sausu"))
print(r4,list(r5)) # <zip object at 0x00000155BC0FAC88> [(4, 'whw'), (5, 'naroo'), (6, 'sausu')]
print(list(r5)) # [] —— 取完一次就没得了! ### filter
r6 = filter(lambda x:x>2,[1,2,3,4,5])
print(r6,list(r6)) # <filter object at 0x0000022E538E1B38> [3, 4, 5]
print(list(r6)) # [] —— 取完一次就没得了!

reduce、map、zip、filter使用记录的更多相关文章

  1. python一些内建函数(map,zip,filter,reduce,yield等)

    python一些内建函数(map,zip,filter,reduce,yield等) map函数 Python实际上提供了一个内置的工具,map函数.这个函数的主要功能是对一个序列对象中的每一个元素应 ...

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

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

  3. python之map、filter、reduce、lambda函数 转

    python之map.filter.reduce.lambda函数  转  http://www.cnblogs.com/kaituorensheng/p/5300340.html 阅读目录 map ...

  4. python的 map,filter, reduce, enumerate

    一, map     #基本的map运用都可以用解析去替代,复杂的仍然需要定义函数,利用map去做 map(函数, 序列) 将序列的各项经过函数处理, 然后返回到一个新列表中. #itertools. ...

  5. Python 之map、filter、reduce

    MAP 1.Python中的map().filter().reduce() 这三个是应用于序列的内置函数,这个序列包括list.tuple.str. 格式: 1>map(func,swq1[,s ...

  6. Python一个有意思的地方:reduce、map、filter

    今天阅读了关于Python函数式编程的系列文章,地址在这里: http://www.cnblogs.com/huxi/archive/2011/06/24/2089358.html 里面提到了四个内建 ...

  7. Swift函数编程之Map、Filter、Reduce

    在Swift语言中使用Map.Filter.Reduce对Array.Dictionary等集合类型(collection type)进行操作可能对一部分人来说还不是那么的习惯.对于没有接触过函数式编 ...

  8. Spark RDD/Core 编程 API入门系列之map、filter、textFile、cache、对Job输出结果进行升和降序、union、groupByKey、join、reduce、lookup(一)

    1.以本地模式实战map和filter 2.以集群模式实战textFile和cache 3.对Job输出结果进行升和降序 4.union 5.groupByKey 6.join 7.reduce 8. ...

  9. 闭包 -> map / floatMap / filter / reduce 浅析

    原创: 转载请注明出处 闭包是自包含的函数代码块,可以在代码中被传递和使用 闭包可以捕获和存储其所在上下文中任意常量和变量的引用.这就是所谓的闭合并包裹着这些常量和变量,俗称闭包.Swift 会为您管 ...

  10. ES6 数组遍历方法的实战用法总结(forEach,every,some,map,filter,reduce,reduceRight,indexOf,lastIndexOf)

    目录 forEach every some map filter reduce && reduceRight indexOf lastIndexOf 前言 ES6原生语法中提供了非常多 ...

随机推荐

  1. 05.AutoMapper 之配置验证(Configuration Validation)

    https://www.jianshu.com/p/5901a5d1ef15 配置验证(Configuration Validation) 手写映射配置代码虽然繁琐,但具有可测试的优点.AutoMap ...

  2. hadoop面试复习笔记(1)

    0.Mappereduce采用的是Master/Slaves模型 1.Hadoop是一个开源软件框架,支持支持大数据集的存储和处理.Apache Hadoop是存储和处理大数据的解决方案你是因为: ( ...

  3. sql:union 与union的使用和区别

    SQL UNION 操作符 UNION 操作符用于合并两个或多个 SELECT 语句的结果集. 请注意,UNION 内部的 SELECT 语句必须拥有相同数量的列.列也必须拥有相似的数据类型.同时,每 ...

  4. android中的rn项目更新gradle及补充二

    修改build.gradle的版本,com.android.tools.build:gradle:2.1.0, 改为更高的,然后更改gradle/wrapper/gradle-wrapper.prop ...

  5. java多图片上传

    2017-09-16 <script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2 ...

  6. 集合类Hash Set,LinkedHashSet,TreeSet

    集合(set)是一个用于存储和处理无重复元素的高效数据结构.映射表(map)类似于目录,提供了使用键值快速查询和获取值的功能. HashSet类是一个实现了Set接口的具体类,可以使用它的无参构造方法 ...

  7. 爬虫之request相关请求

    一.解析json格式数据 (1) # (1)解析json 对象数据 # import requests # 返回的数据进行解析 # response = requests.get('http://ht ...

  8. [转]实际项目中如何使用Git做分支管理 (A successful Git branching model)

    来自 https://nvie.com/posts/a-successful-git-branching-model/ In this post I present the development m ...

  9. Codeforces 976 正方格蛇形走位 二维偏序包含区间 度数图构造 贪心心火牧最大dmg

    A #include <bits/stdc++.h> using namespace std; typedef unsigned long long ull; int main() { i ...

  10. github readme 添加图片预览

    ![img](https://github.com/lanshengzhong/mina_alan/blob/master/screenshot/2.gif) ![图片加载失败的时候就会显示这段话]( ...