我正在寻找某种方法来使这个嵌套的 for 循环更加 Pythonic。具体来说,如果字典中存在数据,我如何遍历三个变量的唯一组合,并写入文件?
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")