This is my code
import nltk
freq_dist = nltk.FreqDist(words)
print freq_dist.keys()[:50] # 50 most frequent tokens
print freq_dist.keys()[-50:] # 50 least frequent tokens
And I am getting this error message:
ImportError: cannot import name compat
Screenshot 1
Screenshot 2
You're trying to import the entirety of nltk when you probably only need a small portion. try editing your code to
from nltk import FreqDist
freq_dist = FreqDist(words)
print freq_dist.keys()[:50] # 50 most frequent tokens
print freq_dist.keys()[-50:] # 50 least frequent tokens