转载-Python3中map函数的问题
来源:互联网 发布:1100lu.us最新域名是啥 编辑:程序博客网 时间:2024/06/10 01:34
出处:http://blog.csdn.net/u010376788/article/details/48230257
返回结果如下:
但是,在Python3中返回结果如下:
如果想要得到Python2的那种结果,即返回list列表,那么必须用list作用于map,如下:
Python3中map函数
在Python2中map函数会返回一个list列表,如代码:
- >>> def f(x, y): return (x, y)
- >>> l1 = [ 0, 1, 2, 3, 4, 5, 6 ]
- >>> l2 = [ ’Sun’, ‘Mon’, ‘Tue’, ‘Wed’, ‘Thu’, ‘Fri’, ‘Sat’ ]
>>> def f(x, y): return (x, y)>>> l1 = [ 0, 1, 2, 3, 4, 5, 6 ]>>> l2 = [ 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat' ]
返回结果如下:
- >>> map(f, l1, l2)
- [(0, ‘Sun’), (1, ‘Mon’), (2, ‘Tue’), (3, ‘Wed’), (4, ‘Thu’), (5, ‘Fri’), (6, ‘Sat’)]
>>> map(f, l1, l2)[(0, 'Sun'), (1, 'Mon'), (2, 'Tue'), (3, 'Wed'), (4, 'Thu'), (5, 'Fri'), (6, 'Sat')]
但是,在Python3中返回结果如下:
- >>> map(f1, l1, l2)
- <map object at 0x00000000021DA860>
>>> map(f1, l1, l2)<map object at 0x00000000021DA860>
如果想要得到Python2的那种结果,即返回list列表,那么必须用list作用于map,如下:
- >>> list(map(f1, l1, l2))
- [(0, ‘Sun’), (1, ‘Mon’), (2, ‘Tue’), (3, ‘Wed’), (4, ‘Thu’), (5, ‘Fri’), (6, ‘Sat’)]
>>> list(map(f1, l1, l2))[(0, 'Sun'), (1, 'Mon'), (2, 'Tue'), (3, 'Wed'), (4, 'Thu'), (5, 'Fri'), (6, 'Sat')]
</div>
阅读全文
0 0
- 转载-Python3中map函数的问题
- Python3中map函数的问题
- python3中map的问题
- python3的map函数显示问题
- python3中map函数的改动
- python3中输出map的问题
- python3的map问题
- TypeError: unhashable type: 'matrix'解决方法 以及 Python3下map函数的显示问题、 python numpy中nonzero()的用法
- python2和python3 map函数的区别
- Python3.4中filter函数,map函数和reduce函数
- Python3.4中filter函数,map函数和reduce函数
- Python3.4中filter函数,map函数和reduce函数
- python3 map函数
- python3 map函数
- 关于python3中round()函数的四舍五入问题
- Python3中的map问题
- python学习——Python3.x版本中filter(),map()函数的变化
- Python学习笔记: Python3中map、filter、reduce函数
- 人工智能在教育方面应用的思考(一)
- 当你还不能写出自己满意的程序时,你就不要去睡觉
- oracle用户管理
- thinkphp复习
- FusionCharts数值格式设置
- 转载-Python3中map函数的问题
- 如何在Hadoop中控制Map&Reduce任务的数量
- android Error:Execution failed for task ':app:transformClassesWithJarMergingForRelease' 解决方法大全
- 机器学习经典书籍&论文(转载)
- Python错误IndentationError: unexpected indent
- ApplicationMaster启动流程
- tcp与udp的区别汇总
- android五种数据存储方式
- 中计播客,让新闻流动起来(内有彩蛋)