在for循环python中调用多个列表

2024-09-29 01:33:14 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用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中为我写多次来重复。。 我怎么能解决这个问题呢。谢谢

^{pr2}$

Tags: 脚本列表fork5pr2试图用k7catlist
2条回答

您要做的是,展开嵌套列表。你可以这样做

for parName in (item for items in catlist for item in items):
for parName in itertools.chain.from_iterable(catlist):

相关问题 更多 >