当我尝试将旧的 python 代码库运行到 python3 时,我遇到了上述运行时错误。代码如下所示。
index = map(lambda x: x[0], self.history).index(state)
最佳答案
在 Python 3 中,map
不返回 list
,而是返回 map object
- 参见:
index = map(lambda x: x[0], [(1,2),(3,4)])
print( type(index) )
# <class 'map'>
你必须使用 list()
index = list(map(lambda x: x[0], self.history)).index(state)
关于python - 属性错误 : 'map' obejct has no attribute 'index' (python 3),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33717314/