Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions nested_data_answers.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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())
Expand All @@ -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?
# ----------------------------------------------------------
Expand All @@ -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'])):
Expand Down