Function: Fundamentals, 2/14, Dictionary creation

https://app.dataquest.io/m/315/functions%3A-fundamentals/2/built-in-functions

Where in the code (or how) are the Keys for the content_ratings created ?
To me, it seems as if only the iteration values would appear .

ratings = ['4+', '4+', '4+', '9+', '12+', '12+', '17+', '17+']
content_ratings = {}

for rating in ratings:
    if rating in content_ratings:
        content_ratings[rating] += 1
    else:
        content_ratings[rating] = 1
        
print(content_ratings)

Hi @tfel4139,

The keys in content_ratings are created by means of content_ratings[rating] at each iteration and represent unique values of the list ratings.

So by writing content_rating[rating] it creates the key if it is not already there ?

It creates a new key if doesn’t exist yet, but if this key already exists, then this code updates its value.