如何将两个列表连接在一起但频率不同

我有两个列表,比如说:

list1 = ["red","blue","yellow"]
list2 = ["frog","lion","tiger","ant","shrew","bee"]

我想循环两个列表的串联,但是我希望list1的每个值都与list2的每个值串联,然后再移至list1的下一个值。也就是说,结果将显示红色青蛙,红色狮子,红色老虎,红色蚂蚁,红色sh,红色蜂,蓝色青蛙等。

我不知道如何错开循环。

sunnygirl126 回答:如何将两个列表连接在一起但频率不同

listColourAnimal = []
for colour in list1:
    for animal in list2:
        listColourAnimal.append(colour + ' ' + animal)

print(listColourAnimal)
本文链接:https://www.f2er.com/3118064.html

大家都在问