https://github.com/famousdraw

TypeError: 'dict_keys' object is not subscriptable

study nlp in PYTHON page 17

 

使用FreqDist时,出现了如下报错:

TypeError: 'dict_keys' object is not subscriptable

我一开始使用的方法是:

fdist = FreqDist(dist).keys()
dist_max=set(fdist[0:50])

只需要在第一行加上list就解决了,代码如下:

fdist = list(FreqDist(dist).keys())
dist_max=set(fdist[0:50])

posted on 2021-06-25 11:50  红色MINI  阅读(521)  评论(0编辑  收藏  举报

导航