예제 #1
0
boroughcon = csv.reader(boroughfile, delimiter=',')
popfile = open('zipCodes.csv', 'r')
popcon = csv.reader(popfile, delimiter=',')


# remove the duplicates
def clean(list):
    checked = []
    for x in list:
        if x not in checked:
            checked.append(x)
    return checked


# make a dict
boroughs['Manhattan'] = Borough('Manhattan')
boroughs['Brooklyn'] = Borough('Brooklyn')
boroughs['Queens'] = Borough('Queens')
boroughs['Bronx'] = Borough('Bronx')
boroughs['Staten'] = Borough('Staten')
# find the zipcodes in each borough
for zipline in boroughcon:
    zipcode = zipline[0]
    for x in boroughs.keys():
        if zipline[1] == x:
            boroughs[x].addZipcode(zipcode)
# clean
for x in boroughs.keys():
    boroughs[x].zipcodes = clean(boroughs[x].zipcodes)
# calculate the population of each borough
popcon.next()