以下简单代码返回错误,即使使用list()
也是如此
map(max,[1,2,3,4])
Out[123]: <map at 0xdff50f0320>
list(map(max,[1,2,3,4]))
TypeError: 'int' object is not iterable
我使用list
映射对象是为了显示内容;它似乎不是这样工作的。如何查看地图对象?
发布于 2018-08-22 08:04:50
map
将给定的函数应用于随后的可迭代对象的每个元素。您尝试做的是分别获取最多四个整数。由于max
还需要一个可迭代的对象,因此此操作失败。
使用示例:
l = [
[1, 2, 3, 4],
[3.14, 2.7, 6.023, -5],
['Python', 'Java', 'R']
]
large = map(max, l)
for big in large:
print (big)
输出:
4
6.023
R
https://stackoverflow.com/questions/51958209
复制相似问题