I have state, county and aqi data. When I put in function the state name, it gives me the county and county's aqi like this:
pa_dict = county_counter('Pennsylvania')
{'Erie': 7, 'Philadelphia': 12, 'Dauphin': 6, 'Lancaster': 1, 'Berks': 3, 'Lackawanna': 7, 'Washington': 7, 'Allegheny': 21, 'Luzerne': 1, 'Schuylkill': 3, 'Beaver': 4, 'Cambria': 6, 'Monroe': 1, 'Westmoreland': 5, 'Bucks': 5, 'Lawrence': 3, 'Lehigh': 1, 'York': 1, 'Montgomery': 1, 'Adams': 2, 'Northampton': 1, 'Blair': 2}
Then I want to find Washington's aqi data which is 7, but I get a typeerror:
pa_dict = county_counter('Pennsylvania')
print(pa_dict['Washington'])
TypeError Traceback (most recent call last) in 1 pa_dict = county_counter('Pennsylvania') 2 ----> 3 print(pa_dict['Washington'])
TypeError: 'NoneType' object is not subscriptable
How can I fix the error?
edit: here is my first code:
def county_counter(state):
county_dict={}
for county, aqi in aqi_dict[state]:
if county in county_dict:
county_dict[county]+=1
else:
county_dict[county]=1
print(county_dict)
county_counter('Pennsylvania')