Hurricane Analysis step 3

I am on step 3 and need to change the keys in a dictionary to the year.

I have managed to change the keys to the year however when there is multiple entries with the same year it just overwrites the values for that year rather than adding to it.

Any help would be much appreciated

You could have lists for the values of the dictionary.

      if new_dict.get(current_year, 0) == 0:
        new_dict[current_year] = [current_cane] # create list containing current_cane
        new_dict[current_year].append(current_cane) # adds to existing list

Using a list in for each year/key makes it possible for there to be more than one hurricane for each year.

1 Like

I am still getting the same overwriting and only giving me the last value for the year

if you’re checking whether the year is not included in the new dictionary, you should change
hurricane_dictionary.get(current_year, 0) == 0:
new_dict.get(current_year, 0) == 0:

1 Like

Thanks much appreciated