What is causing the syntax error?

This post is in reference to the hurricane data exercise in the data scientist career path.

I am trying to create a dictionary where the values are dictionaries themselves. This exercise is giving me a hard time, but I feel like I’m so close. To explain, I am trying to iterate through names and for each name, create and add a dictionary that contains the data for that hurricane. dict_in_dict is supposed to be the final result, but I don’t understand why there is a syntax error (foo is just the name again).

def unite_lists(names, months, years, max_sustained_winds, areas_affected, damages, deaths): new_dict = {} dict_in_dict = {} lists = [names, months, years, max_sustained_winds, areas_affected, damages, deaths] key = ["Name", "Month", "Years", "Max sustained winds", "Areas Affected", "Damages", "Deaths"] value = [] for i in range(len(names)): name = names[i] for data in lists: value.append(data[i]) new_dict = {name:value for name, value in zip(key, value)} for foo in names: dict_in_dict.update(foo:new_dict) value = [] new_dict = {} return dict_in_dict

On line 13,


Note the inclusion of the curly braces in the argument. See if that works. It gets rid of the syntax error.

1 Like

Thanks so much! That solved my initial problem. I then had to get rid of the second nested loop and it worked.

1 Like