So I am trying to make a comparing script where I basically make if there is matching string then print it out else just print out that it doesn't contain.
My problem right now is that whenever it contains the string it print outs only once which is good but whenever it doesn't find a matching, it prints out alot of not matched strings.
etc:
for words in stackoverflow:
word_random = words #random meaning every loop
#"Hello my name is Python and the World is so amazing What"
#My name is Python and it is amazing!
Matching_keyword = ['Hello', 'World', 'What']
for keyword in Matching_keyword:
if keyword in word_random:
print(keyword)
else:
print(keyword)
Output:
Hello
World
What
Hello
World
What
Hello
World
What
Hello
World
What
Hello
World
What
Hello
World
What
Hello
World
What
Hello
World
....
....
....
The output almost never ends and is alot longer than what the ouput is printed here. As you can see I have at the top a for loop which every loop it goes through it gives a new meaning which I there after compare.
My question is how can I make it so whenever it hits the true it should only print out the keyword once and same goes to the else statement?
I tried to use break but that kills the Matching_keyword loop and prints out only Hello but alot of times
for keyword in Matching_keyword:
if keyword in word_random:
print("Found matching" + keyword)
break
else:
print("Did not find matching")
break