web123456

Python3 type error: 'map object is not subscript able

1. The following statement reports an error python3 TypeError: 'map' object is not subscriptable

map(apply_filters_to_token, sentences)

2. Modify, add "list" to map

return list(map(apply_filters_to_token, sentences))
  • 3. Example analysis
# # Handwriting to read data
     # f = file(path)
     # x = []
     # y = []
     # for i, d in enumerate(f):
     # if i == 0: #Skip the title of line 0
     # continue
     # d = () #Remove line breaks, enter, etc.
     # if not d: #If d is empty, no data
     # continue
     # d = list(map(float, (','))) #d has data, use, separate it and convert it to float
     # (d[1:-1]) #Take the number before the first to the last
     # (d[-1]) #Take the last number
     # print(x)
     # print(y)
     # x = (x)
     # y = (y)