From a14bd02d6ae19786890cfcf9db611f49e7e455d2 Mon Sep 17 00:00:00 2001 From: silij Date: Wed, 25 Oct 2017 10:35:21 -0400 Subject: [PATCH] first change to nesteddata --- nested_data_answers.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/nested_data_answers.py b/nested_data_answers.py index c334d05..159f802 100644 --- a/nested_data_answers.py +++ b/nested_data_answers.py @@ -1,6 +1,6 @@ # 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 +# - 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: @@ -28,28 +28,28 @@ # What is the type of the variable holding the twitter data? # ---------------------------------------------------------- #print type(res) # prints a list of the keys in res - +print type(res) # 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 +62,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 +84,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 +106,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'])):