For part 3 of the Hurricane analysis project my answer is roughly the same as in the given solution but when I check the output of the resultant dictionary I only get one record for each year.
# 3
# Organizing by Year
def organize_by_year(hurricanes):
organized_by_year = {}
for cane in hurricanes:
current_year = hurricanes[cane]["Year"]
current_cane = hurricanes[cane]
if current_year not in organized_by_year:
organized_by_year[current_year] = [current_cane]
else:
organized_by_year[current_year].append(current_cane)
return organized_by_year
# create a new dictionary of hurricanes with year and key
hurricanes_by_year = organize_by_year(hurricanes)
print(hurricanes_by_year[1961])
When printing a year with two hurricanes I recieve the same name twice instead of two different names not sure the source of this issue something about how the records are being assigned to organized_by_year
def create_dictionary(names, months, years, max_sustained_winds, areas_affected, updated_damages, deaths):
"""Create dictionary of hurricanes with hurricane name as the key and a dictionary of hurricane data as the value."""
hurricanes = dict()
num_hurricanes = len(names)
for i in range(num_hurricanes):
hurricanes[names[i]] = {"Name": names[i],
"Month": months[i],
"Year": years[i],
"Max Sustained Wind": max_sustained_winds[i],
"Areas Affected": areas_affected[i],
"Damage": updated_damages[i],
"Deaths": deaths[i]}
return hurricanes
# create hurricanes dictionary
hurricanes = create_dictionary(names, months, years, max_sustained_winds, areas_affected, updated_damages, deaths)
I think I may just redownload the notebook start fresh because I’m not exactly sure yet what the issue is.