【发布时间】:2020-03-08 01:46:35
【问题描述】:
我有两个列表,比如说:
list1 = ["red", "blue", "yellow"]
list2 = ["frog", "lion", "tiger", "ant", "shrew", "bee"]
我想循环连接两个列表,但我希望 list1 的每个值与 list2 的每个值连接,然后再转到 list1 的下一个值。即结果会说红蛙、红狮、红虎、红蚂蚁、红鼩、红蜜蜂、蓝蛙等。
我不知道如何错开循环。
【问题讨论】:
-
看看嵌套循环。这应该是一个很好的提示,可以让您继续前进。如果您需要解决方案,只需发表另一条评论。嵌套循环教程:tutorialspoint.com/python/python_nested_loops.htm
-
我想,
itertools.product(list1, list2)就是你要找的东西
标签: python function loops concatenation