我试图用python编写脚本。我需要避免重复相同的任务,并希望写入一个。
catlist1 = ['s0.05-k5-a1.0' , 's0.05-k5-a3.0' , 's0.05-k5-a7.0' , 's0.05-k5-a10.0' ]
catlist2 = ['s0.05-k7-a1.0' , 's0.05-k7-a3.0' , 's0.05-k7-a7.0' , 's0.05-k7-a10.0']
catlist3 = ['s0.07-k5-a1.0' , 's0.07-k5-a3.0' , 's0.07-k5-a7.0' , 's0.07-k5-a10.0' ]
catlist4 = ['s0.07-k7-a1.0' , 's0.07-k7-a3.0' , 's0.07-k7-a7.0' , 's0.07-k7-a10.0']
catlist = [catlist1 ,catlist2 ,catlist3 ,catlist4 ]
我需要调用for循环中的每个列表。我在这个单循环中调用所有列表。我可以通过在catlist1中再次写入多次并再次在catlist2中重复执行此操作。 我怎么能解决这个问题。谢谢
for parName in catlist:
category = '/home/x/Desktop/rouge/ROUGE/Experiments/'
for root, subFolders, files in os.walk(category + parName):
#i = 0
(head, filename) = os.path.split(root)
print filename
#some function that is will re
答案 0 :(得分:5)
for parName in itertools.chain.from_iterable(catlist):
答案 1 :(得分:2)
调用您要执行的操作,展平嵌套列表。你可以这样做
for parName in (item for items in catlist for item in items):