1
該函數返回一個單一的國家和人口,但我需要返回所有人口在列,但跳過第6行變函數返回整列
def findpop(state=None):
f = open(getMediaPath("population_state_reduced (2).csv"), "rt")
index = 1
for line in f:
if index > 3:
parts = line.split(',')
if state is None:
return [(parts[4], int(parts[5]))]
else:
for line in f:
if parts[4] == state.capitalize():
return int(parts[5])
index += 1
print findpop()