A solution problem

in Dictionaries And Frequency Tables mission 10

content_ratings = {‘4+’: 4433, ‘12+’: 1155, ‘9+’: 987, ‘17+’: 622}
total_number_of_apps = 7197

for row in content_ratings:

> percentage_17_plus = content_ratings[‘17+’]
> percentage_15_allowed = content_ratings[‘4+’] + content_ratings[‘9+’] + content_ratings[‘12+’]

the last 2 code should give the dictionary value of their index not the percentage !
I can’t get how it works

Hi @ayahdemerdash, that’s a great question. In the loop, you are using the /= and *= operators to get the percentages, and reassigning the value to the key. By the end of the loop, content_ratings has changed so that the values are now the percentages. You can see the newly updated dictionary if you add print(content_ratings) after your loop.

Just for fun, if you add print(content_ratings) or print(content_ratings[row]) within your loop, you’ll see how the dictionary is being updated. I use this trick a lot when I’m having trouble understanding what is happening in the code or to troubleshoot.

I hope that helps!

1 Like

Many thanks that was really helpful as counting_rating[row] = counting_ratings[row] /total
so it is updated here and saved to counting rating[row]