Why does the following script give the error:
payIntList[i] = payIntList[i] + 1000
TypeError: 'map' object is not subscriptable
payList = []
numElements = 0
while True:
payValue = raw_input("Enter the pay amount: ")
numElements = numElements + 1
payList.append(payValue)
choice = raw_input("Do you wish to continue(y/n)?")
if choice == 'n' or choice == 'N':
break
payIntList = map(int,payList)
for i in range(numElements):
payIntList[i] = payIntList[i] + 1000
print payIntList[i]
In Python 3,
mapreturns an iterable object of typemap, and not a subscriptible list, which would allow you to writemap[i]. To force a list result, writeHowever, in many cases, you can write out your code way nicer by not using indices. For example, with list comprehensions: