Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am getting above run time error, when I am trying to run an old python codebase into python3. The code looks like below.

index = map(lambda x: x[0], self.history).index(state)
like image 640
Sohag Mony Avatar asked Nov 15 '15 07:11

Sohag Mony


1 Answers

In Python 3 map doesn't return list but map object - see:

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

you have to use list()

index = list(map(lambda x: x[0], self.history)).index(state)
like image 91
furas Avatar answered Sep 21 '22 06:09

furas