{'Barack Obama': 'Hawaii'} {'Barack Obama': 'Hawaii', 'George W. Bush': 'Texas', 'Bill Clinton': 'Arkansas'} print type({'Barack Obama': 'Hawaii', 'George W. Bush': 'Texas', 'Bill Clinton': 'Arkansas'}) president_states = {'Barack Obama': 'Hawaii', 'George W. Bush': 'Texas', 'Bill Clinton': 'Arkansas'} print type(president_states) print {17: [1.6, 2.45], 42: [11.6, 19.4], 101: [0.123, 4.89]} print {} print {'Barack Obama': 'Hawaii', 'George W. Bush': 'Texas', 'Bill Clinton': 'Arkansas'}['Bill Clinton'] print president_states['George W. Bush'] print president_states['Benjamin Franklin'] president = 'Barack Obama' print president_states[president] print {'Barack Obama': 'Hawaii', 'George W. Bush': 'Texas', 'Bill Clinton': 'Arkansas'}.keys() print {'Barack Obama': 'Hawaii', 'George W. Bush': 'Texas', 'Bill Clinton': 'Arkansas'}.values() print {'Barack Obama': 'Hawaii', 'George W. Bush': 'Texas', 'Bill Clinton': 'Arkansas'}.items() print {'cheeses': ['cheddar', 'edam', 'emmental']}['cheeses'][1] print {'cheeses': ['cheddar', 'edam', 'emmental']}['cheeses'] president_states = {'Barack Obama': 'Hawaii', 'George W. Bush': 'Texas', 'Bill Clinton': 'Arkansas'} president_states['Ronald Reagan'] = 'California' print president_states print {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 6, 'g': 7, 'h': 8, 'i': 9, 'j': 10} print {'a': 1, 'a': 2, 'a': 3} test_dict = {'a': 1, 'b': 2} print test_dict['a'] test_dict['a'] = 100 print test_dict['a'] print {'a': [1, 2, 3]} import urllib doc_str = urllib.urlopen("https://graph.facebook.com/pythonlang").read() print doc_str print doc_str["about"] print type(doc_str) import json doc_dict = json.loads(doc_str) print type(doc_dict) print doc_dict["about"] print doc_dict.keys() api_key = "paste your api key here and run this cell" import urllib import json url = "http://api.nytimes.com/svc/search/v1/article?format=json&query=python&rank=oldest&api-key=" + api_key response_str = urllib.urlopen(url).read() response_dict = json.loads(response_str) print response_dict.keys() url = "http://api.nytimes.com/svc/search/v1/blarticle" error_str = urllib.urlopen(url).read() error_dict = json.loads(error_str) print error_str response_dict print type(response_dict) print type(response_dict['results']) print type(response_dict['results'][0]) response_dict['results'][0] print len(response_dict['results']) [article['title'] for article in response_dict['results']] [article['body'][:20] for article in response_dict['results']] import urllib print urllib.urlencode({'format': 'json', 'query': 'python', 'rank': 'oldest', 'api-key': '12345'}) base_url = "http://api.nytimes.com/svc/search/v1/article?" query_str = urllib.urlencode({'format': 'json', 'query': 'python', 'rank': 'oldest', 'api-key': '12345'}) request_url = base_url + query_str print request_url topics = ["apple", "banana", "cherry", "coconut", "durian", "lemon", "mango", "orange", "peach", "pear"] import urllib import json import time topics = ["apple", "banana", "cherry", "coconut", "durian", "lemon", "mango", "orange", "peach", "pear"] topic_count = {} for topic in topics: print topic query_str = urllib.urlencode({'query': topic, 'format': 'json', 'api-key': api_key}) request_url = "http://api.nytimes.com/svc/search/v1/article?" + query_str response_str = urllib.urlopen(request_url).read() response_dict = json.loads(response_str) topic_count[topic] = response_dict['total'] time.sleep(0.5) print topic_count