I was trying to practice nested for loops and I was trying to get the outer loop to only run each time. I tried using an if with indexes. The original code below will repeat everything in adj 3 times while I only want it to be once.
adj = ["red", "big", "tasty"]
fruits = ["apple", "banana", "cherry"]
for x in adj:
for y in fruits:
print(x, y)
The output here would be:
red apple red banana red cherry big apple big banana big cherry tasty apple tasty banana tasty cherry
While I only want it to be red apple, big banana, and tasty cherry. So I tried to do the following code below, but I keep getting a general syntax error.
adj = ["red", "big", "tasty"]
fruits = ["apple", "banana", "cherry"]
for x in adj:
print(x)
a = adj.index(x)
print(a)
for y in fruits:
b = fruits.index(y)
print(b)
if int(a) = int(b):
print(x, y)
Does anyone have any suggestions or tips on how to go about this? I am trying to do something similar for my project but I cannot get the x variable to no repeat for repeat for each y?