Hi guys, I’m using the following code to create a new dictionary with years as the key. But when I run the code, it doesn’t show desired output. Notice that the years list has keys with duplicate values (1332 appears twice)
def updating_dict_by_years(names, month, year, max_sustained_wind, areas_affected, damage, death):
hurricane = {}
hurricane_len = len(year)
for i in range(hurricane_len):
hurricane[year[i]] = {"Name": names[i], "Month": month[i], "Year": year[i], "Max Sustained Wind": max_sustained_winds[i], "Areas Affected": areas_affected[i], "Damage": damage[i], "Death": death[i]}
return hurricane
test_dict_by_years = updating_dict_by_years(names, months, years, max_sustained_winds, areas_affected, damages, deaths)
print(test_dict_by_years[1932])
how to return the first value that appears twice in years list as key? thanks~