Python 自然语言处理 P37
fdist1 = FreqDist(text1)
vocabulary1 = fdist1.keys()
vocabulary1[:50]
Traceback (most recent call last):
File "<ipython-input-55-67df9f3ccfe6>", line 1, in <module>
vocabulary1[:50]
TypeError: 'dict_keys' object is not subscriptable
出现错误
修改为
fdist1 = FreqDist(text1)
vocabulary1 = list(fdist1.keys())
vocabulary1[:50]
Out[60]:
['[',
'Moby',
'Dick',
'by',
'Herman',
'Melville',
'1851',
']',
'ETYMOLOGY',
'.',
'(',
'Supplied',
'a',
'Late',
'Consumptive',
'Usher',
'to',
'Grammar',
'School',
')',
'The',
'pale',
'--',
'threadbare',
'in',
'coat',
',',
'heart',
'body',
'and',
'brain',
';',
'I',
'see',
'him',
'now',
'He',
'was',
'ever',
'dusting',
'his',
'old',
'lexicons',
'grammars',
'with',
'queer',
'handkerchief',
'mockingly',
'embellished',
'all']