Question: please answer both in python here is the rest of it. ################ ########## # Phase 3: The Mood of the Nation # ################################### def

################ ########## # Phase 3: The Mood of the Nation # ###################################

please answer both in python

 

here is the rest of it. 

 
def group_tweets_by_state (tweets): """Return a dictionary that aggregates tweets by their neareststate center. The keys of the returned dictionary are state names, andthe values are lists of tweets that appear closer to that statecenter than any other. tweets -- a sequence of tweet abstract datatypes >>> sf = make_tweet ("welcome to san francisco", None, 38, -122)

################ ########## # Phase 3: The Mood of the Nation # ################################### def group_tweets_by_state (tweets): """Return a dictionary that aggregates tweets by their nearest state center. The keys of the returned dictionary are state names, and the values are lists of tweets that appear closer to that state center than any other. tweets -- a sequence of tweet abstract data types >>> sf = make_tweet ("welcome to san francisco", None, 38, -122) >>> ny = make_tweet("welcome to new york", None, 41, -74) >>> two_tweets_by_state = group_tweets_by_state([sf, ny]) >>> len (two_tweets_by_state) 2 >>> california_tweets = two_tweets_by_state['CA'] >>> len(california_tweets) 1 >>> tweet_string(california_tweets[0]) ""welcome to san francisco" @ (38, -122)' || || || tweets_by_state = {} "*** YOUR CODE HERE ***" return tweets_by_state def average_sentiments (tweets_by_state): """Calculate the average sentiment of the states by averaging over all the tweets from each state. Return the result as a dictionary from state names to average sentiment values (numbers). If a state has no tweets with sentiment values, leave it out of the dictionary entirely. Do NOT include states with no tweets, or with tweets that have no sentiment, as 0. 0 represents neutral sentiment, not unknown. sentiment. tweets_by_state A dictionary from state names to lists of tweets averaged_state_sentiments = *** YOUR CODE HERE ***" return averaged_state_sentiments || || || 11 #####

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!