please code in python A tweet is a string that is between 1 and 280 characters long (inclusive). A username is a string of letters and/or digits that is between 1 and 14 characters long (inclusive). A username is mentioned in a tweet by including @username in the tweet (notice the username does not include the @ symbol). A retweet is way to share another user's tweet, and can be identified by the string RT, followed by the original username who tweeted it. Your job is to fill in the function count_retweets_by_username so that it returns a frequency dictionary that indicates how many times each retweeted username was retweeted. tweets = ["This is great! RT @fakeuser: Can you believe this?", "It's the refs! RT @dubsfan: Boo the refs and stuff wargarbal", "That's right RT @ladodgers: The dodgers are destined to win the west!", "RT @sportball: That sporting event was not cool", "This is just a tweet about things @person, how could you", "RT @ladodgers: The season is looking great!", "RT @dubsfan: I can't believe it!", "I can't believe it either! RT @dubsfan: I can't believe it"] def count_retweets_by_username(tweet_list): """ (list of tweets) -> dict of {username: int} Returns a dictionary in which each key is a username that was retweeted in tweet_list and each value is the total number of times this username was retweeted. """ # write code here and update return statement with your dictionary return {} # allow this code to work by implementing count_retweets_by_username function above print(count_retweets_by_username(tweets))
please code in python
A tweet is a string that is between 1 and 280 characters long (inclusive). A username is a string of letters and/or digits that is between 1 and 14 characters long (inclusive). A username is mentioned in a tweet by including @username in the tweet (notice the username does not include the @ symbol). A retweet is way to share another user's tweet, and can be identified by the string RT, followed by the original username who tweeted it.
Your job is to fill in the function count_retweets_by_username so that it returns a frequency dictionary that indicates how many times each retweeted username was retweeted.
tweets = ["This is great! RT @fakeuser: Can you believe this?",
"It's the refs! RT @dubsfan: Boo the refs and stuff wargarbal",
"That's right RT @ladodgers: The dodgers are destined to win the west!",
"RT @sportball: That sporting event was not cool",
"This is just a tweet about things @person, how could you",
"RT @ladodgers: The season is looking great!",
"RT @dubsfan: I can't believe it!",
"I can't believe it either! RT @dubsfan: I can't believe it"]
def count_retweets_by_username(tweet_list):
""" (list of tweets) -> dict of {username: int}
Returns a dictionary in which each key is a username that was
retweeted in tweet_list and each value is the total number of times this
username was retweeted.
"""
# write code here and update return statement with your dictionary
return {}
# allow this code to work by implementing count_retweets_by_username function above
print(count_retweets_by_username(tweets))
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images