gpt4 book ai didi

python - python的map函数

转载 作者:太空宇宙 更新时间:2023-11-04 10:42:40 24 4
gpt4 key购买 nike

>>> dataset
[[1, 3, 4], [2, 3, 5], [1, 2, 3, 5], [2, 5]]
>>> D=map(set,dataset)
>>> D
<map object at 0x0000000002ABF5F8>

当我在python3.3的交互窗口中输入D时,我认为它应该出现:

[set([1, 3, 4]), set([2, 3, 5]), set([1, 2, 3, 5]), set([2, 5]) ]

为什么是 map 对象?

最佳答案

为什么map的结果是一个对象?因为在 documentation for python 3.3据记载它产生结果,因此它是一个生成器。

你可以通过使用阅读它

for i in D:
print i

或者按照 Grijesh 的建议

list(D) 将其转换为列表

关于python - python的map函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19616318/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com