map,zip,reduce函数
lt=range(5,10)
lw=range(8,13)
def mul(a,b):
return a*b
def mul_list(param1,param2):
return_list=[]
for i in range(len(lt)):
return_list.append(mul(lt[i],lw[i]))
print return_list
return return_list
m=mul_list(lt,lw)
map函数
定义一个函数,遍历一个或者多个序列,对其用函数进行处理
map(function,sequence[,seq1,seq2,seq3])
map(...)
map(function, sequence[, sequence, ...]) -> list Return a list of the results of applying the function to the items of
the argument sequence(s). If more than one sequence is given, the
function is called with an argument list consisting of the corresponding
item of each sequence, substituting None for missing values when not all
sequences have the same length. If the function is None, return a list of
the items of the sequence (or a list of tuples if more than one sequence).
def add(a,b,c):
if type(a)==type(b) and type(b)==type(c) and type(a)==type(c):
return a+b+c
else:
print '+ needed all data type the same'
list1=range(1,10)
list2=range(11,20)
list3=range(21,30)
lists=map(add,list1,list2,list3)
print '------------'
print lists
zip(...)
zip(seq1 [, seq2 [...]]) -> [(seq1[0], seq2[0] ...), (...)] Return a list of tuples, where each tuple contains the i-th element
from each of the argument sequences. The returned list is truncated
in length to the length of the shortest argument sequence.
返回list中的每一项是tuple类型
reduce函数:reduce把一个函数作用在一个序列[x1, x2, x3...]上,这个函数必须接收两个参数,reduce把结果继续和序列的下一个元素做累积计算
求5的阶乘
map,zip,reduce函数的更多相关文章
- Python自学笔记-map和reduce函数(来自廖雪峰的官网Python3)
感觉廖雪峰的官网http://www.liaoxuefeng.com/里面的教程不错,所以学习一下,把需要复习的摘抄一下. 以下内容主要为了自己复习用,详细内容请登录廖雪峰的官网查看. Python内 ...
- python Map()和reduce()函数
Map()和reduce()函数 map() 会根据提供的函数对指定序列做映射. 第一个参数 function 以参数序列中的每一个元素调用 function 函数,返回包含每次 function 函 ...
- Python中的map和reduce函数简介
①从参数方面来讲: map()函数: map()包含两个参数,第一个是参数是一个函数,第二个是序列(列表或元组).其中,函数(即map的第一个参数位置的函数)可以接收一个或多个参数. reduce() ...
- Python中map和reduce函数??
①从参数方面来讲: map()函数: map()包含两个参数,第一个是参数是一个函数,第二个是序列(列表或元组).其中,函数(即map的第一个参数位置的函数)可以接收一个或多个参数. reduce() ...
- Python中map和reduce函数
①从参数方面来讲: map()函数: map()包含两个参数,第一个是参数是一个函数,第二个是序列(列表或元组).其中,函数(即map的第一个参数位置的函数)可以接收一个或多个参数. reduce() ...
- Python map,filter,reduce函数
# -*- coding:utf-8 -*- #定义一个自己的map函数list_list = [1,2,4,8,16] def my_map(func,iterable): my_list = [] ...
- python的map和reduce函数
map函数时python的高级内置函数 语法为:map(function, iterable, ...) 参数:function -- 函数iterable -- 一个或多个序列 将function作 ...
- python中map、reduce函数
map函数: 接受一个函数 f 和一个 list .格式:map( f , L),对L中的每个元素,进行f(x)的一个操作. 例如,对于list [1, 2, 3, 4, 5, 6, 7, 8, 9] ...
- Python之filter、map、reduce函数
简介三函数: 高阶函数:一个函数可以接收另一个函数作为参数,这种函数称之为高阶函数. filter.map.reduce三个函数都是高阶函数,且语法都一致:filter/map/reduce(func ...
随机推荐
- Android Weekly Notes Issue #254
Android Weekly Issue #254 April 23rd, 2017 Android Weekly Issue #254 本期内容包括: 如何用Kotlin写一个Gradle Plug ...
- Angular2.js——主从结构
学习这一篇的内容,还回到我们快速起步的应用上来. 主从结构,我们想要做一个英雄的列表,我们希望用户在列表中选中一个英雄,然后这个被选中的英雄出现在详情视图中.主视图是英雄列表,从视图则是被选中英雄的详 ...
- Linux 3.2中回写机制的变革
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://alanwu.blog.51cto.com/3652632/1109952 wri ...
- CTF中怎看phpinfo
CTF中怎么看phpinfo 在比赛中经常遇到phpinfo,这个页面可以看到很多配置信息,我们需要在这么多信息中,着重看一下几个内容: 1.allow_url_fopen和allow_url_inc ...
- Kafka配置及简单命令使用
一. Kafka中的相关概念的介绍 Kafka是一个scala实现的分布式消息中间件,其中涉及到的相关概念如下: Kafka中传递的内容称为message(消息),message 是通过topic(话 ...
- C++ 元编程 —— 让编译器帮你写程序
目录 1 C++ 中的元编程 1.1 什么是元编程 1.2 元编程在 C++ 中的位置 1.3 C++ 元编程的历史 2 元编程的语言支持 2.1 C++ 中的模板类型 2.2 C++ 中的模板参数 ...
- Java中实现多线程关键词整理
Java中的Runable,Callable,Future,FutureTask,ExecutorService,Excetor,Excutors,ThreadPoolExcetor在这里对这些关键词 ...
- hdu1312 Red and Black 简单BFS
简单BFS模版题 不多说了..... 直接晒代码哦.... #include<cstdlib> #include<iostream> #include<cstdio> ...
- mysql语句优化总结(一)
Sql语句优化和索引 1.Innerjoin和左连接,右连接,子查询 A. inner join内连接也叫等值连接是,left/rightjoin是外连接. SELECT A.id,A.nam ...
- C#之自定义特性
在前面介绍的代码中有使用特性,这些特性都是Microsoft定义好的,作为.NET Framework类库的一部分,许多特性都得到了C#编译器的支持. .NET Frmework也允许定义自己的特性. ...