Python map object is not subscriptable -


why following script give error:

payintlist[i] = payintlist[i] + 1000
typeerror: 'map' object not subscriptable

paylist = [] numelements = 0  while true:         payvalue = raw_input("enter pay amount: ")         numelements = numelements + 1         paylist.append(payvalue)         choice = raw_input("do wish continue(y/n)?")         if choice == 'n' or choice == 'n':                          break  payintlist = map(int,paylist)  in range(numelements):          payintlist[i] = payintlist[i] + 1000          print payintlist[i] 

in python 3, map returns iterable object of type map, , not subscriptible list, allow write map[i]. force list result, write

payintlist = list(map(int,paylist)) 

however, in many cases, can write out code way nicer not using indices. example, list comprehensions:

payintlist = [pi + 1000 pi in paylist] pi in payintlist:     print(pi) 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -