Skip to content

Instantly share code, notes, and snippets.

@JeffCohen
Created December 9, 2016 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JeffCohen/c8693203198cc94b64a3db36e736d622 to your computer and use it in GitHub Desktop.
Save JeffCohen/c8693203198cc94b64a3db36e736d622 to your computer and use it in GitHub Desktop.
# Python 3
#
# https://docs.python.org/3/howto/urllib2.html
# http://api.open-notify.org/astros.json
# This code works. Run it to verify.
# Then read the challenge at the bottom of this file.
import urllib.request
import json
url = "http://api.open-notify.org/astros.json"
def whos_in_space():
data = retrieve_space_data()
for person in data['people']:
print(person['name'])
def retrieve_space_data():
with urllib.request.urlopen(url) as response:
json_data = response.read().decode('utf8')
return json.loads(json_data)
whos_in_space()
# Challenge: Can you display the names in alphabetical order?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment