Function: Fundamentals, 2/14, Dictionary creation

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
        content_ratings[rating] = 1

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.