Adding Values to a Dictionary

Screen Link:
https://app.dataquest.io/m/314/dictionaries-and-frequency-tables/7/counting-with-dictionaries
My Code:

opened_file = open('AppleStore.csv')
from csv import reader
read_file = reader(opened_file)
apps_data = list(read_file)


content_ratings = {}
for c_rating in apps_data:
    c_rating = c_rating[10]
    if c_rating in content_ratings:
        content_ratings[c_rating] += 1

What I expected to happen:

What actually happened:

Replace this line with the output/error

I understand this is a conditional statement, but how exactly is it working if nothing has been added to the dictionary yet?

Hi Hunter. On this particular screen we’re not going to start out with a blank dictionary. From the mission instructions:

Create a dictionary named content_ratings where the keys are the unique content ratings and the values are all 0 (the values of 0 are temporary at this point, and they’ll be updated).

Scrolling up in the lesson text, we can see what this is supposed to look like:

Create a dictionary where the keys are the unique content ratings and the values are all 0: {'4+': 0, '9+': 0, '12+': 0, '17+': 0}

On a future screen you’ll start with a blank dictionary and populate it from scratch using an if/else, but here you’ll start with a dictionary that already has keys.

You asked “how exactly is it working”, so I’m curious about what you ended up with for content_ratings when the code runs. I ended up with a blank dictionary (which is what should happen here). Did you get something different?

This is the output as is. Nowhere did it say to populate the dictionary. That was my confusion.

opened_fileTextIOWrapper (<class ‘_io.TextIOWrapper’>)
<_io.TextIOWrapper name=‘AppleStore.csv’ mode=‘r’ encoding=‘UTF-8’>
c_ratingstr (<class ‘str’>)
‘4+’
apps_datalist (<class ‘list’>)
[[‘id’,
‘track_name’,
‘size_bytes’,
‘currency’,
‘price’,
‘rating_count_tot’,
‘rating_count_ver’,
‘user_rating’,
‘user_rating_ver’,
‘ver’,
‘cont_rating’,
‘prime_genre’,
‘sup_devices.num’,
‘ipadSc_urls.num’,
‘lang.num’,
‘vpp_lic’],
[‘284882215’,
‘Facebook’,
‘389879808’,
‘USD’,
‘0.0’,
‘2974676’,
‘212’,
‘3.5’,
‘3.5’,
‘95.0’,
‘4+’,
‘Social Networking’,
‘37’,
‘1’,
‘29’,
‘1’],
[‘389801252’,
‘Instagram’,
‘113954816’,
‘USD’,
‘0.0’,
‘2161558’,
‘1289’,
‘4.5’,
‘4.0’,
‘10.23’,
‘12+’,
‘Photo & Video’,
‘37’,
‘0’,
‘29’,
‘1’],
[‘529479190’,
‘Clash of Clans’,
‘116476928’,
‘USD’,
‘0.0’,
‘2130805’,
‘579’,
‘4.5’,
‘4.5’,
‘9.24.12’,
‘9+’,
‘Games’,
‘38’,
‘5’,
‘18’,
‘1’],
[‘420009108’,
‘Temple Run’,
‘65921024’,
‘USD’,
‘0.0’,
‘1724546’,
‘3842’,
‘4.5’,
‘4.0’,
‘1.6.2’,
‘9+’,
‘Games’,
‘40’,
‘5’,
‘1’,
‘1’],
[‘284035177’,
‘Pandora - Music & Radio’,
‘130242560’,
‘USD’,
‘0.0’,
‘1126879’,
‘3594’,
‘4.0’,
‘4.5’,
‘8.4.1’,
‘12+’,
‘Music’,
‘37’,
‘4’,
‘1’,
‘1’],
[‘429047995’,
‘Pinterest’,
‘74778624’,
‘USD’,
‘0.0’,
‘1061624’,
‘1814’,
‘4.5’,
‘4.0’,
‘6.26’,
‘12+’,
‘Social Networking’,
‘37’,
‘5’,
‘27’,
‘1’],
[‘282935706’,
‘Bible’,
‘92774400’,
‘USD’,
‘0.0’,
‘985920’,
‘5320’,
‘4.5’,
‘5.0’,
‘7.5.1’,
‘4+’,
‘Reference’,
‘37’,
‘5’,
‘45’,
‘1’],
[‘553834731’,
‘Candy Crush Saga’,
‘222846976’,
‘USD’,
‘0.0’,
‘961794’,
‘2453’,
‘4.5’,
‘4.5’,
‘1.101.0’,
‘4+’,
‘Games’,
‘43’,
‘5’,
‘24’,
‘1’],
[‘324684580’,
‘Spotify Music’,
‘132510720’,
‘USD’,
‘0.0’,
‘878563’,
‘8253’,
‘4.5’,
‘4.5’,
‘8.4.3’,
‘12+’,
‘Music’,
‘37’,
‘5’,
‘18’,
‘1’],
[‘343200656’,
‘Angry Birds’,
‘175966208’,
‘USD’,
‘0.0’,
‘824451’,
‘107’,
‘4.5’,
‘3.0’,
‘7.4.0’,
‘4+’,
‘Games’,
‘38’,
‘0’,
‘10’,
‘1’],
[‘512939461’,
‘Subway Surfers’,
‘156038144’,
‘USD’,
‘0.0’,
‘706110’,
‘97’,
‘4.5’,
‘4.0’,
‘1.72.1’,
‘9+’,
‘Games’,
‘38’,
‘5’,
‘1’,
‘1’],
[‘362949845’,
‘Fruit Ninja Classic’,
‘104590336’,
‘USD’,
‘1.99’,
‘698516’,
‘132’,
‘4.5’,
‘4.0’,
‘2.3.9’,
‘4+’,
‘Games’,
‘38’,
‘5’,
‘13’,
‘1’],
[‘359917414’,
‘Solitaire’,
‘101943296’,
‘USD’,
‘0.0’,
‘679055’,
‘9673’,
‘4.5’,
‘4.5’,
‘4.11.2’,
‘4+’,
‘Games’,
‘38’,
‘4’,
‘11’,
‘1’],
[‘469369175’,
‘CSR Racing’,
‘524803072’,
‘USD’,
‘0.0’,
‘677247’,
‘2029’,
‘4.5’,
‘4.5’,
‘4.0.1’,
‘4+’,
‘Games’,
‘37’,
‘5’,
‘10’,
‘1’],
[‘924373886’,
‘Crossy Road - Endless Arcade Hopper’,
‘165471232’,
‘USD’,
‘0.0’,
‘669079’,
‘1087’,
‘4.5’,
‘4.5’,
‘1.5.4’,
‘9+’,
‘Games’,
‘38’,
‘5’,
‘13’,
‘1’],
[‘575658129’,
‘Injustice: Gods Among Us’,
‘1829599232’,
‘USD’,
‘0.0’,
‘612532’,
‘410’,
‘4.5’,
‘4.5’,
‘2.15.1’,
‘12+’,
‘Games’,
‘39’,
‘5’,
‘13’,
‘1’],
[‘506627515’,
‘Hay Day’,
‘113641472’,
‘USD’,
‘0.0’,
‘567344’,
‘4887’,
‘4.5’,
‘4.5’,
‘1.33.134’,
‘4+’,
‘Games’,
‘38’,
‘5’,
‘18’,
‘1’],
[‘500116670’,
‘Clear Vision (17+)’,
‘37879808’,
‘USD’,
‘0.99’,
‘541693’,
‘69225’,
‘4.5’,
‘4.5’,
‘1.1.3’,
‘17+’,
‘Games’,
‘43’,
‘5’,
‘1’,
‘1’],
[‘479516143’,
‘Minecraft: Pocket Edition’,
‘147787776’,
‘USD’,
‘6.99’,
‘522012’,
‘1148’,
‘4.5’,
‘4.5’,
‘1.1’,
‘9+’,
‘Games’,
‘37’,
‘1’,
‘11’,
‘1’],
[‘293778748’,
‘PAC-MAN’,
‘100849664’,
‘USD’,
‘0.0’,
‘508808’,
‘99’,
‘3.0’,
‘4.5’,
‘6.3.5’,
‘4+’,
‘Games’,
‘38’,
‘5’,
‘10’,
‘1’],
[‘341232718’,
‘Calorie Counter & Diet Tracker by MyFitnessPal’,
‘152700928’,
‘USD’,
‘0.0’,
‘507706’,
‘181’,
‘4.5’,
‘4.5’,
‘7.16’,
‘4+’,
‘Health & Fitness’,
‘37’,
‘5’,
‘19’,
‘1’],
[‘440045374’,
‘DragonVale’,
‘153074688’,
‘USD’,
‘0.0’,
‘503230’,
‘282’,
‘4.5’,
‘4.5’,
‘3.15.0’,
‘4+’,
‘Games’,
‘37’,
‘5’,
‘10’,
‘1’],
[‘295646461’,
‘The Weather Channel: Forecast, Radar & Alerts’,
‘199734272’,
‘USD’,
‘0.0’,
‘495626’,
‘5893’,
‘3.5’,
‘4.5’,
‘8.11’,
‘4+’,
‘Weather’,
‘37’,
‘0’,
‘33’,
‘1’],
[‘487119327’,
‘Head Soccer’,
‘121319424’,
‘USD’,
‘0.0’,
‘481564’,
‘8518’,
‘5.0’,
‘5.0’,
‘5.4.1’,
‘4+’,
‘Games’,
‘40’,
‘4’,
‘11’,
‘1’],
[‘284815942’,
‘Google – Search made just for mobile’,
‘179979264’,
‘USD’,
‘0.0’,
‘479440’,
‘203’,
‘3.5’,
‘4.0’,
‘27.0’,
‘17+’,
‘Utilities’,
‘37’,
‘4’,
‘33’,
‘1’],
[‘596402997’,
‘Despicable Me: Minion Rush’,
‘147123200’,
‘USD’,
‘0.0’,
‘464312’,
‘444’,
‘4.5’,
‘4.5’,
‘4.6.0’,
‘9+’,
‘Games’,
‘38’,
‘5’,
‘16’,
‘1’],
[‘466965151’,
‘The Sims™ FreePlay’,
‘695603200’,
‘USD’,
‘0.0’,
‘446880’,
‘1832’,
‘4.5’,
‘4.0’,
‘5.29.0’,
‘12+’,
‘Games’,
‘38’,
‘5’,
‘12’,
‘1’],
[‘293622097’,
‘Google Earth’,
‘37214208’,
‘USD’,
‘0.0’,
‘446185’,
‘1359’,
‘3.5’,
‘3.5’,
‘7.1.6’,
‘4+’,
‘Travel’,
‘43’,
‘5’,
‘30’,
‘1’],
[‘350642635’,
‘Plants vs. Zombies’,
‘105379840’,
‘USD’,
‘0.99’,
‘426463’,
‘680’,
‘5.0’,
‘4.0’,
‘1.9.13’,
‘9+’,
‘Games’,
‘38’,
‘0’,
‘5’,
‘1’],
[‘582654048’,
‘Sonic Dash’,
‘186687488’,
‘USD’,
‘0.0’,
‘418033’,
‘419’,
‘4.5’,
‘4.5’,
‘3.7.1’,
‘4+’,
‘Games’,
‘37’,
‘5’,
‘7’,
‘1’],
[‘352683833’,
‘Groupon - Deals, Coupons & Discount Shopping App’,
‘127382528’,
‘USD’,
‘0.0’,
‘417779’,
‘914’,
‘4.5’,
‘4.5’,
‘17.7’,
‘12+’,
‘Shopping’,
‘37’,
‘4’,
‘10’,
‘1’],
[‘543186831’,
‘8 Ball Pool™’,
‘86776832’,
‘USD’,
‘0.0’,
‘416736’,
‘19076’,
‘4.5’,
‘4.5’,
‘3.9.1’,
‘4+’,
‘Games’,
‘38’,
‘5’,
‘10’,
‘1’],
[‘422667065’,
‘Tiny Tower - Free City Building’,
‘124720128’,
‘USD’,
‘0.0’,
‘414803’,
‘4536’,
‘4.5’,
‘4.5’,
‘3.3.12’,
‘12+’,
‘Games’,
‘38’,
‘4’,
‘1’,
‘1’],
[‘457446957’,
‘Jetpack Joyride’,
‘108813312’,
‘USD’,
‘0.0’,
‘405647’,
‘877’,
‘4.5’,
‘4.5’,
‘1.9.24’,
‘9+’,
‘Games’,
‘38’,
‘5’,
‘3’,
‘1’],
[‘510461758’,
‘Bike Race - Top Motorcycle Racing Games’,
‘120187904’,
‘USD’,
‘0.0’,
‘405007’,
‘4053’,
‘4.5’,
‘5.0’,
‘7.3.11’,
‘4+’,
‘Games’,
‘38’,
‘5’,
‘9’,
‘1’],
[‘284993459’,
‘Shazam - Discover music, artists, videos & lyrics’,
‘147093504’,
‘USD’,
‘0.0’,
‘402925’,
‘136’,
‘4.0’,
‘4.5’,
‘11.0.3’,
‘12+’,
‘Music’,
‘37’,
‘3’,
‘16’,
‘1’],
[‘860822992’,
‘Kim Kardashian: Hollywood’,
‘239976448’,
‘USD’,
‘0.0’,
‘397730’,
‘467’,
‘4.5’,
‘4.5’,
‘6.6.0’,
‘12+’,
‘Games’,
‘38’,
‘5’,
‘1’,
‘1’],
[‘307727765’,
‘Doodle Jump’,
‘48741376’,
‘USD’,
‘0.99’,
‘395261’,
‘88’,
‘4.5’,
‘4.5’,
‘3.17.6’,
‘4+’,
‘Games’,
‘37’,
‘0’,
‘1’,
‘1’],
[‘651510680’,
‘Trivia Crack’,
‘265484288’,
‘USD’,
‘0.0’,
‘393469’,
‘34’,
‘4.5’,
‘3.5’,
‘2.40’,
‘4+’,
‘Games’,
‘37’,
‘5’,
‘26’,
‘1’],
[‘708600202’,
‘WordBrain’,
‘110595072’,
‘USD’,
‘0.0’,
‘391401’,
‘82’,
‘4.5’,
‘4.5’,
‘1.21.1’,
‘4+’,
‘Games’,
‘38’,
‘5’,
‘1’,
‘1’],
[‘930574573’,
‘Sniper 3D Assassin: Shoot to Kill Gun Game’,
‘157851648’,
‘USD’,
‘0.0’,
‘386521’,
‘10332’,
‘5.0’,
‘5.0’,
‘1.17.6’,
‘17+’,
‘Games’,
‘40’,
‘5’,
‘9’,
‘1’],
[‘526641427’,
‘Flow Free’,
‘20669440’,
‘USD’,
‘0.0’,
‘373857’,
‘3428’,
‘4.5’,
‘4.5’,
‘2.9’,
‘4+’,
‘Games’,
‘38’,
‘5’,
‘11’,
‘1’],
[‘297368629’,
‘Lose It! – Weight Loss Program and Calorie Counter’,
‘182054912’,
‘USD’,
‘0.0’,
‘373835’,
‘402’,
‘4.0’,
‘4.5’,
‘8.0.2’,
‘4+’,
‘Health & Fitness’,
‘37’,
‘3’,
‘1’,
‘1’],
[‘304878510’,
‘Skype for iPhone’,
‘133238784’,
‘USD’,
‘0.0’,
‘373519’,
‘127’,
‘3.5’,
‘4.0’,
‘6.35.1’,
‘4+’,
‘Social Networking’,
‘37’,
‘0’,
‘32’,
‘1’],
[‘698255242’,
‘Geometry Dash Lite’,
‘69076992’,
‘USD’,
‘0.0’,
‘370370’,
‘2650’,
‘5.0’,
‘4.5’,
‘2.11’,
‘4+’,
‘Games’,
‘37’,
‘4’,
‘1’,
‘1’],
[‘488627858’,
‘Draw Something’,
‘84379648’,
‘USD’,
‘2.99’,
‘360974’,
‘3’,
‘4.5’,
‘4.5’,
‘3.0.17’,
‘4+’,
‘Games’,
‘38’,
‘5’,
‘1’,
‘1’],
[‘366247306’,
‘▻Sudoku’,
‘71002112’,
‘USD’,
‘0.0’,
‘359832’,
‘17119’,
‘4.5’,
‘5.0’,
‘5.4’,
‘4+’,
‘Games’,
‘40’,
‘5’,
‘7’,
‘1’],
[‘333903271’,
‘Twitter’,
‘210569216’,
‘USD’,
‘0.0’,
‘354058’,
‘452’,
‘3.5’,
‘4.0’,
‘6.79.1’,
‘17+’,
‘News’,
‘37’,
‘2’,
‘33’,
‘1’],
[‘454638411’,
‘Messenger’,
‘275729408’,
‘USD’,
‘0.0’,
‘351466’,
‘892’,
‘3.0’,
‘3.0’,
‘119.0’,
‘4+’,
‘Social Networking’,
‘37’,
‘1’,
‘33’,
‘1’],
[‘323229106’,
‘Waze - GPS Navigation, Maps & Real-time Traffic’,
‘94139392’,
‘USD’,
‘0.0’,
‘345046’,
‘3040’,
‘4.5’,
‘4.5’,
‘4.24’,
‘4+’,
‘Navigation’,
‘37’,
‘5’,
‘36’,
‘1’],
[‘310738695’,
‘Zillow Real Estate - Homes for Sale & for Rent’,
‘132632576’,
‘USD’,
‘0.0’,
‘342969’,
‘88478’,
‘4.5’,
‘4.5’,
‘10.4.5’,
‘4+’,
‘Lifestyle’,
‘37’,
‘5’,
‘1’,
‘1’],
[‘305343404’,
‘Tumblr’,
‘151573504’,
‘USD’,
‘0.0’,
‘334293’,
‘919’,
‘4.0’,
‘4.0’,
‘8.6’,
‘17+’,
‘Social Networking’,
‘37’,
‘5’,
‘16’,
‘1’],
[‘403858572’,
‘Fruit Ninja®’,
‘163801088’,
‘USD’,
‘0.0’,
‘327025’,
‘82’,
‘4.5’,
‘4.0’,
‘2.5.1’,
‘4+’,
‘Games’,
‘38’,
‘5’,
‘13’,
‘1’],
[‘387428400’,
‘Infinity Blade’,
‘624107810’,
‘USD’,
‘0.99’,
‘326482’,
‘177050’,
‘5.0’,
‘5.0’,
‘1.4.1’,
‘12+’,
‘Games’,
‘43’,
‘5’,
‘13’,
‘1’],
[‘447188370’,
‘Snapchat’,
‘203038720’,
‘USD’,
‘0.0’,
‘323905’,
‘576’,
‘2.5’,
‘3.0’,
‘10.9.2.0’,
‘12+’,
‘Photo & Video’,
‘37’,
‘0’,
‘22’,
‘1’],
[‘363590051’,
‘Netflix’,
'12501606\n[variable truncated]
listtype (<class ‘type’>)
list
content_ratingsdict (<class ‘dict’>)
{}
read_filereader (<class ‘_csv.reader’>)
<_csv.reader at 0x7fa1fae66278>

Moved to separate post.

@Nicole I would suggest asking your question in a separate, new post. Let’s allow this post to focus only on the original question. Plus, it’s better to have separate questions in separate posts to make them easier to find.

1 Like

Ah I see now, I was a little confused by how it returns results when you click on the community discussion button. This is the only post related to this section of the mission, I see now it just searches tags and not a catch-all post for each section.

Hi April, I did exactly what you mentioned above, but my output didn’t increment the dictionary value by 1. (The instruction was: Check whether c_rating exists as a key in content_ratings . If it exists, then increment the dictionary value at that key by 1 (the key is equivalent to the value stored in c_rating )

output: {‘4+’: 4433, ‘9+’: 987, ‘12+’: 1155, ‘17+’: 622}

my expected output was: {‘4+’: 4434, ‘9+’: 988, ‘12+’: 1156, ‘17+’: 623}

did I misinterpret something?