0

I have two lists, let's say:

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

I want to loop the concatenation of the two lists but I want each value of list1 to concatenate with every value of list2 before moving on to the next value of list1. I.e, results would say red frog, red lion, red tiger, red ant, red shrew, red bee, blue frog, etc.

I can't figure out how I would stagger the loop.

Elsybelsy
  • 61
  • 6
  • 2
    Have a look at nested loops. That should be a good hint to get you going forward. If you need a solution just drop another comment. Nested loop tutorial: https://www.tutorialspoint.com/python/python_nested_loops.htm – Jason Chia Nov 12 '19 at 10:57
  • I think, `itertools.product(list1, list2)` is what you are looking for – han solo Nov 12 '19 at 11:01

1 Answers1

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

print(listColourAnimal)
Sachin Patel
  • 499
  • 2
  • 12