I have a list of of words which I want to find in a text file.
Right now I'm trying the any method to iterate through lines in a file.
It returns True or False correctly so it's working fine.
My question though is if it's possible to see which word it found? I can see with my code and the text which word was found but I would like to use it in the code somehow if it's possible.
An example of what I mean below. This code returns True or False if any of the words are in the line.
list_of_words = ['apple', 'banana', 'lemon']
with open(file, 'r') as f:
lines = f.readlines()
for line in lines:
x = any(word in line for word in list_of_words)
print(x)