I have list of a list of dictionaries on hurricane data called list_hurricane
, which looks like
**Simplified View**
Hurricane A Hurricane B
[[{key1:value1, key2:value2,...}],[{key1:value1, key2:value2,...}]]
**Full View**:
[[{'name': 'Cuba I', 'month': 'October', 'year': 1924, 'max_sustained_wind': 165, 'area_affected': ['Central America', 'Mexico', 'Cuba', 'Florida', 'The Bahamas'], 'damage': 'Damages not recorded', 'death': 90}], [{'name': 'San Felipe II Okeechobee', 'month': 'September', 'year': 1928, 'max_sustained_wind': 160, 'area_affected': ['Lesser Antilles', 'The Bahamas', 'United States East Coast', 'Atlantic Canada'], 'damage': '100M', 'death': 4000}], [{'name': 'Bahamas', 'month': 'September', 'year': 1932, 'max_sustained_wind': 160, 'area_affected': ['The Bahamas', 'Northeastern United States'], 'damage': 'Damages not recorded', 'death': 16}], [{'name': 'Cuba II', 'month': 'November', 'year': 1932, 'max_sustained_wind': 175, 'area_affected': ['Lesser Antilles', 'Jamaica', 'Cayman Islands', 'Cuba', 'The Bahamas', 'Bermuda'], 'damage': '40M', 'death': 3103}], etc...
I am trying to use the year as a key
and return each dictionary as the value
. The problem is some years have multiple hurricanes/dictionaries.
I tried appending and thought I fixed it but now it is just showing None
for those years with duplicates.
Here is what I have that returns None
:
years[i]
= [1924, 1928, 1932, 1932, 1933....]
dic_years = {}
for i in range(len(list_hurricane)):
if years[i] in dic_years:
dic_years[years[i]] = list_hurricane[i-1].append(list_hurricane[i])
else:
dic_years[years[i]] = list_hurricane[i]
Does anyone know how I could combine the lists, so that the key returns all the hurricanes for that year?