예제 #1
0
def census(sortby):
    if sortby == 1:
        popList.sort(key = lambda x: x.last)
    elif sortby == 2:
        popList.sort(key = lambda x: x.first)
    elif sortby == 3:
        popList.sort(key = lambda x: x.age)
    elif sortby == 4:
        popList.sort(key = lambda x: x.sex)

    out = "data/census.csv"
    data = ["Last, First, Sex, Age, Race".split(',')]
    for each in popList:
        info = "%s,%s,%s,%s,%s" % (each.last, each.first, each.sex, str(each.age), each.race)
        info = info.split(",")
        data.append(info)
    tools.csv_writer(data, out)
예제 #2
0
 def census(self, sortby):
     if sortby == 1:
         self.popList.sort(key = lambda x: x.last)
     elif sortby == 2:
         self.popList.sort(key = lambda x: x.first)
     elif sortby == 3:
         self.popList.sort(key = lambda x: x.age)
     elif sortby == 4:
         self.popList.sort(key = lambda x: x.sex)
 
     out = "data/" + self.name + "census.csv"
     data = ["Name, Focus, popSize".split(',')]
     data.append([self.name, self.focus, self.popSize])
     data.append(["Last, First, Sex, Age, Race".split(',')])
     for each in self.popList:
         info = "%s,%s,%s,%s,%s" % (each.last, each.first, each.sex, str(each.age), each.race)
         info = info.split(",")
         data.append(info)
     tools.csv_writer(data, out)