小编imp*_*ato的帖子

在Python中使用多个列表进行循环

我正在寻找解决方案。目前,我有两个元素列表:

column_width = ["3", "3", "6", "8", "4", "4", "4", "4"]
fade = ["100", "200", "300"]
Run Code Online (Sandbox Code Playgroud)

我想要实现的是创建for循环,它将为我提供以下输出:

column-3-fade-100
column-3-fade-200
column-6-fade-300
column-8-fade-100
column-4-fade-200
...
Run Code Online (Sandbox Code Playgroud)

嵌套for循环对我不起作用:

for i in fade:
    for c in column_width_a:
        print("column-{0}-fade-{1}".format(c, i))
Run Code Online (Sandbox Code Playgroud)

还有其他产生此输出的方法吗?

python loops for-loop nested

12
推荐指数
1
解决办法
188
查看次数

标签 统计

for-loop ×1

loops ×1

nested ×1

python ×1