Python コンソールで NLTK の本「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']