AttributeError: 'map' obejct has no attribute 'index' (python 3)

I get the above runtime errors when I try to run the old python code base in python3. The code is as follows.

index = map(lambda x: x[0], self.history).index(state)
+4
source share
1 answer

In Python 3 it mapdoes not return list, but map object- see:

index = map(lambda x: x[0], [(1,2),(3,4)])
print( type(index) )
# <class 'map'>

you need to use list()

index = list(map(lambda x: x[0], self.history)).index(state)
+5
source

Source: https://habr.com/ru/post/1615938/


All Articles