Answered step by step
Verified Expert Solution
Question
1 Approved Answer
# 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
# 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
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started