I’m just making an assumption here and saying that your variables sad_words and happy_words are lists?
if they are lists, then your code is basically creating a variable total_words into a really long string. This is not what you want to do as it will create problems when it gets to the for word in total_words loop since it will loop over each character instead of the word you were hoping to loop over in total_words.
I have the code below that outputs the correct neutral tweet count and explains the logic behind the neutral variable.
happy_words = ['great', 'excited', 'happy', 'nice', 'wonderful', 'amazing', 'good', 'best']
sad_words = ['sad', 'bad', 'tragic', 'unhappy', 'worst']
number_of_neutral_tweets = 0
total_words = sad_words + happy_words
for tweet in tweets:
neutral = True # Assigning neutral to be a boolean "True"
for word in total_words:
if word in tweet:
neutral = False # Converts neutral to false if any happy or sad word is found in the tweet
break # breaks the for loop and starts over
number_of_neutral_tweets += 1 if neutral else 0 # Will only increment if neutral is true
print(number_of_neutral_tweets) # Print out 2 as there are only 2 neutral tweets