Rectangle 27 0

You have to convert it to list first:

new_vocab= list(vocabulary1)
...= new_vocab[:50]

nltk - TypeError: 'map' object is not subscriptable error in Python 3 ...

python nltk typeerror
Rectangle 27 0

I had the same problem. Use vocabulary1 = list(fdist1). You can then access the 50 most frequent words by vocabulary1[:50].

TypeError: 'map' object is not subscriptable - NLTK book with Python 3...

python-3.x nltk
Rectangle 27 0

Looks like you are using Python 3. In Python 3 dict.keys() returns an iteratable but not indexable object. The most simple (but not so efective) solution would be:

vocab = list(fdist1.keys())
vocab = list(fdist1)

NLTK python error: "TypeError: 'dict_keys' object is not subscriptable...

python nltk
Rectangle 27 0

Probably the interface changed and you need to do list(vocabulary1)[:50] or something like that. see help(map)

>>> a=lambda x: x+2
>>> b = map(a, [1,2,3])
>>> b[0:2]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'map' object is not subscriptable
>>> list(b)
[3, 4, 5]

Big thanx! list(vocabulary1)[:50] - is working! The more general question i am interested: is there any docs on changes in syntax for Python 3 from Python 2 for NLTK? I afraid i will face other problems soon

TypeError: 'map' object is not subscriptable - NLTK book with Python 3...

python-3.x nltk
Rectangle 27 0

In Python 3 .keys() returns an iterator, which you can't slice. Convert it to a list before slicing.

fdist1 = FreqDist(text1)
vocabulary1 = fdist1.keys()
x = list(vocabulary1)[:50]
# or...
vocabulary1 = list(fdist1.keys())
x = vocabulary1[:50]

nltk - TypeError: 'map' object is not subscriptable error in Python 3 ...

python nltk typeerror