I try the following codes but it pops up "TypeError: unhashable type: 'list"
>>> import nltk
>>> text = nltk.corpus.brown.words(categories = 'news')
>>> def zif(text):
fdist = nltk.FreqDist(text)
import pylab
word = fdist.keys()
x = []
y = []
index = []
for i in range(0,len(set(text)),1):
x.extend(word[i:i+1])
y.extend(fdist[word[i:i+1]])
index.extend('i+1')
pylab.plot(index, y,'b')
pylab.title('zipf law')
pylab.xlabel('word rank')
pylab.ylabel('word frequency')
pylab.show()
>>> zif(text)
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
zif(text)
File "<pyshell#3>", line 10, in zif
y.extend(fdist[word[i:i+1]])
File "C:\Python27\lib\site-packages\nltk\probability.py", line 495, in __getitem__
return self.get(sample, 0)
TypeError: unhashable type: 'list'
Any suggestions or solutions? thanks indeed.