Trying to conceptually understand dictionaries in IF statement (7/15)

Hello, I am trying to understand the code below conceptutally. Can anyone explain to me why in the IF statement we write c_rating in paranthesis of content_rating? Why can’t we just say content_rating += 1?
opened_file = open(‘AppleStore.csv’)
from csv import reader
read_file = reader(opened_file)
apps_data = list(read_file)
content_ratings = {‘4+’:0, ‘9+’:0, ‘12+’:0, ‘17+’:0}
for babu_utho in apps_data[1:]:
c_rating = babu_utho[10]
if c_rating in content_ratings:
content_ratings[c_rating] += 1

Please use triple back ticks ``` to format a code block. See the post below on how to format code block using triple back ticks.

Because you can’t add numbers DIRECTLY to a dictionary (dict). You will get an error.

The IF portion of the code is let Python know which key IN the dictionary that you are referring to.
dict = { key : value }
dict[ key ] = value

So the content_ratings[c_rating] is letting Python know which key (c_rating) in the dict (‘content_ratings’) you are referring to.

Hope that helped.

Thank you very much for your reply! yes that helps a lot.

Happy Sunday :slight_smile: