Skip to content

Instantly share code, notes, and snippets.

@AlexDel
Created January 10, 2012 14:03
Show Gist options
  • Save AlexDel/1589239 to your computer and use it in GitHub Desktop.
Save AlexDel/1589239 to your computer and use it in GitHub Desktop.
NLTK. Ex 2.17 Write a function that finds the 50 most frequently occurring words of a text that are not stopwords.
def freq_non_stopwords(text):
stopwords = nltk.corpus.stopwords.words('english')
clean_list = [w for w in text if w.lower() not in stopwords] #убираем частотные слова
freqdist = nltk.probability.FreqDist(clean_list)
return freqdist.keys()[:50] #возвращаем 50 первых нечастотных слов
@ZmUPL
Copy link

ZmUPL commented Feb 8, 2015

How can we print the result

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment