Hello everyone! I’m working on the Hurricane Analysis project. In the step 3, we have to create a dictionary with all the data about every hurricane.
First, I have tried this code:
def hurricane_data(names, months, years, max_sustained_winds, areas_affected, damages, deaths):
for i in range(0, len(names)):
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": damages[i]}}
return hurricanes
But it only printed the data about the last hurricane on the list. However, this code printed the data of all the hurricanes:
`def hurricane_data(names, months, years, max_sustained_winds, areas_affected, damages, deaths):
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": damages[i]} for i in range(0, len(names))}
return hurricanes`
Why the second one works and the e doesn’t???