I am attempting to find the sum of prices for vehicles in the state of texas. Below is the code that I have attempted
Autos = [
{'make': 'Jeep', 'Model': 'Wrangler', 'price': 35000, 'state': 'colorado'},
{'make': 'Jeep', 'Model': 'Wrangler', 'price': 33250, 'state': 'texas'},
{'make': 'Jeep', 'Model': 'Wrangler', 'price': 52300, 'state': 'colorado'},
{'make': 'Jeep', 'Model': 'Wrangler', 'price': 75000, 'state': 'colorado'},
{'make': 'Jeep', 'Model': 'Wrangler', 'price': 28500, 'state': 'texas'},
{'make': 'Jeep', 'Model': 'Wrangler', 'price': 35000, 'state': 'colorado'},
]
for d in Autos:
if d['state'] == 'texas':
sum([d['price']])
I am able to get the list of prices using the following. But I need the sum to calculate the average.
for d in Autos:
if d['state'] == 'texas':
print(d['price'])
33250
28500
sum. You should try to think about the problem in those separate steps, and you should study techniques for processing a list.