zips=csv.reader(open("zipCodes.csv","rb"),delimiter=',') z3=list(zips) #dictionary holding all zip codes' population from zipcodes.csv zippop={} #dictionary for borough, takes user input boroughs={userboro:0} #fill in zipcode for i in range(1,len(z3)): zippop[z3[i][0]]=z3[i][10] # instantiate Borough class in the dictionary # class has 3 parameters, name, zipcodes as an array and sum of population in zip codes in the borough boroughs[userboro]=Borough(userboro) boroughs[userboro].zipcodes=[] boroughs[userboro].sumpopul=0 #first check if in boroughs.csv zip exists #if we find user defined borough name proceed to zip population dictionary #append the zip code to the class object #zort is a list as (zipcode, population in the zipcode) for i in range(0,len(b1)): if b1[i][1] == userboro: zipcode = Zipcode(int(b1[i][0])) if str(zipcode.number) in zippop.keys(): if zippop[str(zipcode.number)]!='': det=int(zippop[str(zipcode.number)])
keep = [] for entry in list: if entry not in found: found.append(entry) keep.append(entry) return keep with open('boroughs.csv') as f: rows = csv.reader(f, delimiter=',') for row in rows: thiszip = Zipcode(row[0]) rowentry = row[1] if (rowentry.lower() == borough.name): borough.addZipcode(thiszip.number) borough.zipcodes = makeunique(borough.zipcodes) with open('zipCodes.csv') as f: rows = csv.reader(f, delimiter=',') rows.next() for row in rows: if (row[10] != ''): rowzip = row[1] rowpop = float(row[10].strip()) for line in borough.zipcodes: if (int(rowzip) == int(line)): borough.addPopulation(rowpop) borough.findAverage() print borough.average