-
-
Save sansyrox/92b513878669548be4c448f53476ac85 to your computer and use it in GitHub Desktop.
Import a JSON file. If condition is met, print two attributes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from json import load as json_load | |
with open("sample_input.json") as input_fh: | |
people = json_load(input_fh) | |
for person in people["people"]: | |
if person["age"] >= 30: | |
print("Name: {name}, City: {city}".format(name=person["name"], city=person["city"])) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"people":[ | |
{ | |
"name":"John", | |
"age":30, | |
"city":"Chicago" | |
}, | |
{ | |
"name":"Beth", | |
"age":40, | |
"city":"New York" | |
}, | |
{ | |
"name":"Lucy", | |
"age":25, | |
"city":"Los Angeles" | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment