Python Forum

Full Version: Omit pronoun/common words when searching in Python
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have a python program to count most appearing words in a file. Now I want to omit most common words from the file. I have written 2 program for this. How can combine them or call internally?

--Snippet of code

def order_bag_of_words(bag_of_words, desc=False):
    words = [(word, cnt) for word, cnt in bag_of_words.items()]
    return sorted(words, key=lambda x: x[1], reverse=desc)
-- snippet of stop words

from nltk.corpus import stopwords
from nltk.tokenize import wordpunct_tokenize

stop_words = set(stopwords.words('english')) # creating a set makes the 
searching faster
print (stop_words)
So you have a way to get words you want to ignore. And you have a way to sort words. I'm confused on what you need help with, isn't that everything?