0
why do I get an error? I just want to print the country_counts variable
4 Answers
+ 6
You have to put the country names between quotes:
country_list = ["australia", "australia", "uganda"]
Also, dictionaries do not have .add() method. Use .update() instead. Finally, you have to consider the case when there already is a country entry in the dictionary, before you print the country_counts.
To sum up, it should go like this:
country_list = ["australia", "australia" , "uganda"]
country_counts = {}
for country in country_list:
if country not in country_counts :
country_counts.update({country: 1})
else:
country_counts[country] += 1
print(country_counts)
+ 1
you are missing an indented block... just like the error message tells you
0
how would you fix it? I don't understand where I should indent it. sorry for the noob question
0
thanks a lot guys I got it!