0

how to print output one time?

i have written two for loops i.e for loop within for loop followed by if statement the problem is when the condition satisfies it prints multiple output. for word1 in a: for word2 in b: if word1==something and word2==something: print (word2) The output is word2 word2 word2........

5th May 2021, 8:12 PM
syed fahad
syed fahad - avatar
2 Answers
+ 2
Maybe your "if" statement is satisfied more than 1 time? You can use boolean, declare it as False, set it to true inside 'if' statement, and break out of outer loop if boolean = True
5th May 2021, 8:18 PM
Michal Doruch