我试图在每次迭代中对一个项目执行不同的操作。用python帮助我完成下面的代码
router1 = "10.11.12.13"
router2 = "10.11.12.14"
tunnel1, tunnel2, tunnel3, tunnel4 = "tunnel01","tunnel02","tunnel03","tunnel04"
router = [router1, router2]
tunnel = [tunnel1, tunnel2, tunnel3, tunnel4]
for each in router:
for eachtunnel in tunnel:
#Here in the first iteration I have to bring up tunnel1 on router1 and shut remaining tunnels on both router 1 and 2.
#In the second iteration I have to bring up tunnel2 on router1 and shut remaining tunnels on both the routers.
它应该持续到8个迭代,其中只有一个隧道是向上的,其余的是向下的。你知道吗
在本例中,我将每个路由器的隧道数设为4,但可能会有所不同。请建议我如何才能做到这一点。你知道吗
这应该管用。我会在隧道和路由器上循环两次,如果内环的路由器和隧道与外环的路由器和隧道匹配,我们就补上,否则就补上
样本输出为
一个糟糕的列表理解方法将是。你知道吗
还可以使用
itertools
创建笛卡尔积itertools.product,然后遍历它们。你知道吗这个怎么样:
为了便于阅读,我对变量名做了一些修改。你知道吗
相关问题 更多 >
编程相关推荐