143k views
0 votes
Write code that will read the contents of umich_buildings.json and load its value into the gobal variable umich_buildings. Note that umich_buildings will be a list.

1 Answer

1 vote

Answer:

import json

umich_buildings = []

with open("umich_buildings.json", "r") as json_file:

content = json.load(json_file)

json_file.close()

for value in content:

umich_buildings.append(value)

print("the resultant is : ", umich_buildings)

Step-by-step explanation:

The python source code gets information from a json file, it imports the json package and opens and assigns the json file "umich_building" to the variable "json_file" and continuously parse the json to python with the load() method, then append the items to the global list variable "umich_buildings"

User Lwe
by
5.1k points