【发布时间】:2012-11-26 06:42:50
【问题描述】:
我正在寻找一些方法来让这个嵌套的 for 循环更符合 Python 风格。具体来说,如果字典中存在数据,我如何遍历三个变量的唯一组合,并写入文件?
foo,bar = {},{} #filling of dicts not shown
with open(someFile,'w') as aFile:
for year in years:
for state in states:
for county in counties:
try:foo[year,state,county],bar[state,county]
except:continue
aFile.write("content"+"\n")
【问题讨论】: