Question: # Sample Twitter feed tweets = [ Happy #IlliniFriday!, It is a pretty campus, isn't it , #illini?, Diving into the last weekend of
# Sample Twitter feed
tweets
"Happy #IlliniFriday!",
It is a pretty campus, isn't it #illini?",
"Diving into the last weekend of winter break like... #ILLINI #JoinTheFight",
"Are you wearing your Orange and Blue today, #Illini Nation?"
# Dictionary to store hashtag counts
hashtagcounts
# Iterate through each tweet
for tweet in tweets:
# Split the tweet into words
words tweet.split
# Iterate through the words to find hashtags
for word in words:
# Check if the word starts with a #
if word.startswith#:
# Remove special characters and convert to lowercase
hashtag word.lower
# Update the count in the dictionary
hashtagcountshashtag hashtagcounts.gethashtag
# Sort the dictionary by count descending and then by hashtag ascending
sortedhashtagcounts sortedhashtagcounts.items keylambda x: x x
# Print the sorted hashtag counts
printsortedhashtagcounts
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
