python3的map问题
来源:互联网 发布:为不善乎显明之中者 编辑:程序博客网 时间:2024/05/21 09:13
在Python2中map函数会返回一个list列表,如代码:
1
2
3
>>>
def
f(x, y):
return
(x, y)
>>> l1
=
[
0
,
1
,
2
,
3
,
4
,
5
,
6
]
>>> l2
=
[
'Sun'
,
'Mon'
,
'Tue'
,
'Wed'
,
'Thu'
,
'Fri'
,
'Sat'
]
返回结果如下:
1
2
>>>
map
(f, l1, l2)
[(
0
,
'Sun'
), (
1
,
'Mon'
), (
2
,
'Tue'
), (
3
,
'Wed'
), (
4
,
'Thu'
), (
5
,
'Fri'
), (
6
,
'Sat'
)]
但是,在Python3中返回结果如下:
1
2
>>>
map
(f1, l1, l2)
<
map
object
at
0x00000000021DA860
>
如果想要得到Python2的那种结果,即返回list列表,那么必须用list作用于map,如下:
1
2
>>>
list
(
map
(f1, l1, l2))
[(
0
,
'Sun'
), (
1
,
'Mon'
), (
2
,
'Tue'
), (
3
,
'Wed'
), (
4
,
'Thu'
), (
5
,
'Fri'
), (
6
,
'Sat'
)]
阅读全文
0 0
- python3的map问题
- python3中map的问题
- Python3中map函数的问题
- python3中输出map的问题
- 转载-Python3中map函数的问题
- python3的map函数显示问题
- Python3中的map问题
- python3的input问题
- Python3的编码问题
- python3的编码问题
- python3 的编码问题
- Python3的编码问题
- python3中map函数的改动
- Python3 zip,lambda,map,reduce的使用
- python2和python3 map函数的区别
- TypeError: unhashable type: 'matrix'解决方法 以及 Python3下map函数的显示问题、 python numpy中nonzero()的用法
- Python3碰到的编码问题
- 自己遇到的python3问题
- docker 7 打包 docker 的镜像
- window系统安装两个jdk
- Apache-Mina (IoBuffer putString getString方法注意事项)
- python编程求字符串s1和s2共同元素
- java面试题(二)-多线程
- python3的map问题
- Java8元空间代替持久代
- 如何保证线程按顺序执行
- OSI参考模型——传输层:TCP、UDP协议详解
- 时间差1
- Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF environment vari
- Spring Data JPA入门
- 书的复制 解题报告(动态规划dp四边形不等式优化)
- 部署war包到Tomcat根目录(测试有效)