If the dictionary outside the loop is empty (content_ratings), then what’s the point of checking if c_rating exists as a key in this dictionary? It should be obvious that it doesn’t exist as the dictionary is empty, but the answer shows something different. I don’t get why.
Because you’ll loop through an entire dataset. The dictionary is empty before the loop starts, but during the loop it will be filled.
When the loop starts, the dict is empty so
if c_rating in content_ratings is False and the you’ll have
contante_ratings[c_rating] = 1 running inside the
else. But when the loop moves to next app, it may have the same
c_rating as the first one that you just add do the dict so
if c_rating in content_ratings will be True and
content_ratings[c_rating] will be incremented by 1. Otherwise every key in your dict would have the same value 1.
Great! Now I get it. Thank you Otavios!
Always good to help, @tomasz.markielow.