Beispiel #1
0
"""

# from borough import *
from borough import Borough

# reuse the functions in problem 4
from problem3 import getzippopulation, getboroughzipcode

from sys import argv as bname


if __name__ == "__main__":
    # get the population and borough information from the data in dictionary form
    populationdic = getzippopulation()
    boroughdic = getboroughzipcode()

    # turn the input into the captalized form
    bname = bname[1].split(" ")[0].capitalize()

    # initialize the object in Borough class
    BOROUGH = Borough(bname)

    # put the data stored from two dictions into the object
    for zp in boroughdic[bname]:
        if zp in populationdic:
            BOROUGH.addZipcode(zp)
            BOROUGH.addPopulation(populationdic[zp])

    # use the class function to get the average number
    print BOROUGH.PopuPerZip()
    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