Overall, I have a code which reads through a data file with data about countries which participated in the Olympics. This portion of code checks if in the year requested there are medallists from any countries and writes it in the dict if there are any. Basically, I am trying to count the amount of Gold, Silver and Bronze medals for each country in this year. That's why I've made a dictionary however for some reason "KeyError: 'Norway'" occurs, and I'm unsure how to fix that.
A bit more info: medals_dict is an empty dictionary. There is no dictionary full_country, full_country is just a text string
Here's the code:
def total_medal_counter(year_in_data, full_country, medal):
global year
global medals_dict
if year == year_in_data:
if full_country in medals_dict:
if medal in full_country:
medals_dict[full_country][medal] = medals_dict[full_country][medal] + 1
print(medals_dict)
else:
medals_dict[full_country][medal] = 1
print(medals_dict)