TypeError: 'dict_keys' object is not subscriptable

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']
发布了44 篇原创文章 · 获赞 0 · 访问量 1315

猜你喜欢

转载自blog.csdn.net/qq_41664688/article/details/104247294
今日推荐