I have this json file:
[
{"industry": "food", "price": 100.0, "name": "mcdonald's"},
{"industry": "food", "price": 90.0, "name": "tacobell"},
{"industry": "food", "price": 150.0, "name": "Subway"},
{"industry": "Cars", "price": 90.0, "name": "Audi"}
]
This is my code:
import json
from pprint import pprint
with open('firm_list.json', encoding='utf-8') as data_file:
data = json.loads(data_file.read())
pprint(data)
result_list=[]
for json_dict in data:
result_list.append(json_dict['price'])
result_list=[json_dict['price'] for json_dict in data]
result_list.sort(reverse= True)
print(result_list)
I want to print a list of firms in the food industry and respective prices, which is sorted by the price, with the highest price appearing first. But my code print in the list also the firm from the car industry. How can I print just the firms from the food industry? Is it possible to have the name of the firms on the list too?