欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

“TypeError: 'dict_keys' object is not subscriptable”

程序员文章站 2022-07-14 23:49:47
...

问题出在《Python自然语言处理》第18页的代码


属于python3会出现的情况

改为如下即可:

from nltk.book import *
fdist1=FreqDist(text1)
vocabulary1=fdist1.keys()
vocab=list(vocabulary1)
print("vocabulary1=",vocab)
fdist1.plot(50,cumulative=True)


“TypeError: 'dict_keys' object is not subscriptable”