我在 Python 控制台中重复 NLTK 书籍“Natural Language Processing with Python”中的示例。(我使用 Pycharm 2.7.2、Windows 7、Python 3.3.2)。我是 Python 新手,不知道如何解决。我今天从https://github.com/nltk/nltk下载了最新的 NLTK,但没关系。
在第 39 页,它抛出一个错误:TypeError: 'map' object is not subscriptable
>>> fdist1 = FreqDist(text1)
>>> fdist1
Out[7]: <FreqDist with 19317 samples and 260819 outcomes>
>>> vocabulary1 = fdist1.keys()
>>> vocabulary1[:50]
Traceback (most recent call last):
File "C:\Python33\lib\site-packages\IPython\core\interactiveshell.py", line 2732, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-9-30d7de8cfb37>", line 1, in <module>
vocabulary1[:50]
TypeError: 'map' object is not subscriptable
预期的输出应该是:
>>> vocabulary1[:50]
[',', 'the', '.', 'of', 'and', 'a', 'to', ';', 'in', 'that', "'", '-',
'his', 'it', 'I', 's', 'is', 'he', 'with', 'was', 'as', '"', 'all', 'for',
'this', '!', 'at', 'by', 'but', 'not', '--', 'him', 'from', 'be', 'on',
'so', 'whale', 'one', 'you', 'had', 'have', 'there', 'But', 'or', 'were',
'now', 'which', '?', 'me', 'like']