diff --git a/nested_data_answers.py b/nested_data_answers.py index c334d05..8bbb53b 100644 --- a/nested_data_answers.py +++ b/nested_data_answers.py @@ -1,14 +1,3 @@ -# Import twitter_data.py in twitter_data in the current script -# - Note the file name does not include the extension ('.py') -# - The * is a wildcard. It's telling python I want to import -# everything from the file twitter_data.py -from twitter_data import * -# What is the difference between the above statement and the following: -# import wtitter_data # You will need to comment the import above and uncomment this one to experiment - # HINT: the code below assumes we are using the first type of import: 'from twitter_data import *' - - - # Basic strategy: # ======================================================================================== # 1. Check the type of the data structure @@ -31,25 +20,25 @@ # If it's a dictionary, what are its keys? -# If it's a list, how many elements does it have?, and +# If it's a list, how many elements does it have?, and # what is the type of its first element? # ---------------------------------------------------------- #print res.keys() -#print type(res['statuses']) +#print type(res['statuses']) -# Why the key "search_metadata" is not relevant +# Why the key "search_metadata" is not relevant # to our purposes? # ---------------------------------------------------------- # What is the type associated to the key 'statuses'? # ---------------------------------------------------------- -#print type(res['statuses']) +#print type(res['statuses']) # If it's a dictionary, what type are its keys? -# If it's a list, how many elements does it have?, and +# If it's a list, how many elements does it have?, and # what is the type of its first element? # ---------------------------------------------------------- #print len(res['statuses']) # 3 elements @@ -62,15 +51,15 @@ # print type(res['statuses'][i]) -# If it's the first element its a dictionary, +# If it's the first element its a dictionary, # what are its keys? -# If it's a list, how many elements does it have?, and +# If it's a list, how many elements does it have?, and # what is the type of its first element? # ---------------------------------------------------------- # print res['statuses'][0].keys() # print type(res['statuses'][0].keys()[0]) -# If it's a dictionary, how many keys does +# If it's a dictionary, how many keys does # the first dictionary have? # ---------------------------------------------------------- #print len(res['statuses'][0].keys()) @@ -84,7 +73,7 @@ # print len(res['statuses'][i].keys()) -# Nested under 'statuses', there are dictionaries, +# Nested under 'statuses', there are dictionaries, # do they have a key that contains the username I am looking for? # If so, what is the type and value associated to it? # ---------------------------------------------------------- @@ -106,16 +95,16 @@ # associated to it? # ---------------------------------------------------------- # 'name' -#print type(res['statuses'][0]['user']['name']) +#print type(res['statuses'][0]['user']['name']) #print res['statuses'][0]['user']['name'] # Since you know there are three tweets in the database # You also know there is an equal number of usernames # corresponding to the users who twitted -# By answerin the questions above, you have already found +# By answerin the questions above, you have already found # the first name -# Can you iterate through the twitter data, so that you +# Can you iterate through the twitter data, so that you # access the other three names with a single print statement? # ---------------------------------------------------------- #for i in range(len(res['statuses'])): diff --git a/twitter_data.py b/twitter_data.py index 9177978..806a47d 100644 --- a/twitter_data.py +++ b/twitter_data.py @@ -1,18 +1,7 @@ -res = { - "search_metadata": { - "count": 3, - "completed_in": 0.015, - "max_id_str": "536624519285583872", - "since_id_str": "0", - "next_results": "?max_id=536623674942439424&q=University%20of%20Michigan&count=3&include_entities=1", - "refresh_url": "?since_id=536624519285583872&q=University%20of%20Michigan&include_entities=1", - "since_id": 0, - "query": "University+of+Michigan", - "max_id": 536624519285583872 - }, + "statuses": [ { - "contributors": None, + "contributor1": None, "truncated": False, "text": "RT @mikeweber25: I'm decommiting from the university of Michigan thank you Michigan for the love and support I'll remake my decision at the\u2026", "in_reply_to_status_id": None, @@ -54,9 +43,9 @@ "retweeted": False, "coordinates": None, "entities": { - "symbols": [], + "symbols": [1,2,3], "user_mentions": [], - "hashtags": [], + "hashtags": [1,2,3], "urls": [] }, "in_reply_to_screen_name": None, @@ -706,4 +695,3 @@ } ] } -