Having a little trouble understanding "dict[]
" command, if anyone could help me with this, it would be much appreciated.
This is the code I have so far: (I've put in where and what I need help with) import csv
inputYear = input('Please enter the year: ')
inFile = open('babyQldAll.csv', 'rU')
cvsFile = csv.reader(inFile, delimiter=',')
dict = {}
for row in cvsFile:
year, name, count, gender = row
if (year == inputYear) and (gender == 'Boy'):
dict[name] = count
print('Popular boy names in year %s are:' % inputYear)
# According to information in 'dict', print (name, count) sorted by 'name' in alphabetical order
print("Print boy names... ")
inFile.close()
using the code above I'm trying to get an outcome of:
Popular boy names in year "2010" are: Aidan 119, Alex 224, Derek 143, Steven 212, Tom 111.....
from the following input:
File 2010:
2010, Steven, 212, Boy
2010, Mary, 423, Girl
2010 , Tom, 111, Boy
2010, Jessica, 223, Girl
(and so on)