Python Incrementing
Question: I am writing a program that will accept text as an input.

The program has a value "tone" that starts at 0. Tone increments by +1 when it
sees a word in that text that is also in a list of words "posfeats." Tone
increments by -1 when it sees a word in that text that is also in a list of
words "negfeats."

However, my code is returning a 0 for the value "tone" no matter what input
text I give it. I feel that this is due to my faulty Python programming rather
than my algorithm.

Here is the code:

    
    
    import nltk.classify.util
    from nltk.classify import NaiveBayesClassifier
    from nltk.corpus import movie_reviews #importing two corpora, movie_reviews and stopwords
    from nltk.corpus import stopwords
    
    def word_feats(words):
    stops = dict([(word, True) for word in stopwords.words('english')]) #English stopwords
    features = dict([(word, True) for word in words if word not in stops])#features minus stopwords
    return features
    
    def compare(words, negfeats, posfeats):
    sentiment=0
    for word in words:
        if word in negfeats:
            sentiment -= 1
        if word in posfeats:
            sentiment += 1
    return sentiment
    
    
    negReviews = reviews.fileids('neg')
    posReviews = reviews.fileids('pos')
    
    negfeats = [(word_feats(reviews.words(fileids=[f])), 'neg') for f in negReviews]
    posfeats = [(word_feats(reviews.words(fileids=[f])), 'pos') for f in posReviews]
    
    opinion = raw_input("Why don't you tell me about a movie you watched recently?\n\n")
    tone = compare(opinion.split(), negfeats, posfeats)
    print(str(tone)) #THIS KEEPS RETURNING 0
    


Answer: 
    negfeats = [(word_feats(reviews.words(fileids=[f])), 'neg') for f in negReviews]
    posfeats = [(word_feats(reviews.words(fileids=[f])), 'pos') for f in posReviews]
    

Did you mean to have `dict` calls here? `negfeats` and `posfeats` are lists of
`(word, 'neg')` and `(word, 'pos')` tuples. `compare` will search these lists
for words and not find any, because the words are nested in the tuples. Of
course, it'd be better to use `set`s for unordered collections without
duplicates.

