python3.5 如何用map做出和zip同样的效果?
问题描述
如下面这段代码,我想把map和zip做出同样的效果
name=[’a’,’b’,’c’]age=[10,11,12]nation=[’中国’,’にほん’,’Deutsch’]U1=list(zip(name,age,nation))print(U1)U2=map(None,name,age,nation)print(list(U2))
可是显示:
[(’a’, 10, ’中国’), (’b’, 11, ’にほん’), (’c’, 12, ’Deutsch’)]Traceback (most recent call last): File 'F:/python/PT/program/nine neijian3.py', line 8, in <module> print(list(U2))TypeError: ’NoneType’ object is not callable
但是我去掉map里面的None:
U2=map(name,age,nation)print(list(U2))
显示:
print(list(U2))TypeError: ’list’ object is not callable`
请各位大神赐教。
问题解答
回答1:map(lambda a,b,c: (a,b,c), name, age, nation)
回答2:name=[’a’,’b’,’c’]age=[10,11,12]nation=[’中国’,’にほん’,’Deutsch’]U1=list(zip(name,age,nation))print(U1)U2 = map(lambda a,b,c: (a,b,c), name, age, nation)print(list(U2))
第一个报错NoneType ,是用于None object,所以不能输出很正常。NoneType is the type for the None object, which is an object that indicates no value. You cannot add it to strings or other objects.
Python map()方法好像不是你这么用的,据我了解是应该是这个样子的。描述很简单,第一个参数接收一个函数名,第二个参数接收一个可迭代对象。语法map(f, iterable)基本上等于:[f(x) for x in iterable]实例
>>> def add100(x):... return x+100... >>> hh = [11,22,33]>>> map(add100,hh)[111, 122, 133]
http://stackoverflow.com/ques...
相关文章:
1. javascript - jQuery each 方法第三个参数args 如何解释?2. css3 - Typecho 后台部分表单按钮在 Chrome 下出现灵异动画问题,求解决3. java - 阿里的开发手册中为什么禁用map来作为查询的接受类?4. java - 关于i++的一个题目5. apache - 想把之前写的单机版 windows 软件改成网络版,让每个用户可以注册并登录。类似 qq 的登陆,怎么架设服务器呢?6. java - HTTPS双向认证基础上有无必要再进行加签验签?7. javascript - 为什么嵌套的Promise不能按预期捕获Exception?8. ubuntu apt-get install update 无法更新9. javascript - 编程,算法的问题10. webgl - android上类似汽车之家的3d全景照片怎么实现
