Python Dictionaries and Frequency Tables lesson 3 (Counting with Dictionaries)

Screen Link:

My Code:
Maybe i misunderstood the task but if i wanted to automate the process by creating the keys with value of 0 through the loop. I am getting the wrong count:
My original thought process:
\\opened_file = open(‘AppleStore.csv’)
from csv import reader
read_file = reader(opened_file)
apps_data = list(read_file)
content_ratings = {}
ratings = [ ]
for row in apps_data[1:]:
c_rating = row[10]
ratings.append(row[10])
content_ratings[c_rating] = 0
if c_rating in ratings:
content_ratings[c_rating] += 1
print(content_ratings)\\

Replace this line with your code

What I expected to happen:
I expected the actual count:
{‘4+’: 4433, ‘9+’: 987, ‘12+’: 1155, ‘17+’: 622}

What actually happened:
{‘4+’: 1, ‘9+’: 1, ‘12+’: 1, ‘17+’: 1}

Replace this line with the output/error

When i saw the solution it appears that the assignment allowed us to manually input the dictionary entries. But what if the entires where 100s or 1000s of entries. How can i modify my code to append and count properly. Maybe i am overthinking the process?

disregard, the next lesson explains my theory and mindset:
opened_file = open(‘AppleStore.csv’)
from csv import reader
read_file = reader(opened_file)
apps_data = list(read_file)
content_ratings = {}
for row in apps_data[1:]:
c_rating = row[10]
if c_rating in content_ratings:
content_ratings[c_rating] += 1
else:
content_ratings[c_rating] = 1

print(content_ratings)

1 Like