Created
August 25, 2021 07:46
-
-
Save BolajiAyodeji/2f473946c890c2f206b3cd0df869f53f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tweets = [ | |
"Wow, what a great day today!! #sunshine", | |
"I feel sad about the things going on around us. #covid19", | |
"I'm really excited to learn Python with @JovianML #zerotopandas", | |
"This is a really nice song. #linkinpark", | |
"The python programming language is useful for data science", | |
"Why do bad things happen to me?", | |
"Apple announces the release of the new iPhone 12. Fans are excited.", | |
"Spent my day with family!! #happy", | |
"Check out my blog post on common string operations in Python. #zerotopandas", | |
"Freecodecamp has great coding tutorials. #skillup" | |
] | |
happy_words = ['great', 'excited', 'happy', 'nice', 'wonderful', 'amazing', 'good', 'best'] | |
sad_words = ['sad', 'bad', 'tragic', 'unhappy', 'worst'] | |
number_of_happy_tweets = 0 | |
number_of_sad_tweets = 0 | |
number_of_neutral_tweets = 0 | |
happy_tweets = [] | |
sad_tweets = [] | |
sentiment_tweets = happy_tweets + sad_tweets | |
neutral_tweets = [] | |
for tweet in tweets: | |
for word in happy_words: | |
if word in tweet: | |
happy_tweets.append(tweet) | |
for word in sad_words: | |
if word in tweet: | |
sad_tweets.append(tweet) | |
def get_difference(tweets, sentiment_tweets): | |
return set(tweets)-set(sentiment_tweets) | |
non_match = list(get_difference(tweets, sentiment_tweets)) | |
neutral_tweets.append(non_match) | |
number_of_happy_tweets = len(happy_tweets) | |
number_of_sad_tweets = len(sad_tweets) | |
number_of_neutral_tweets = len(neutral_tweets) | |
print(happy_tweets) | |
print(sad_tweets) | |
print(neutral_tweets) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment