Python Forum

Full Version: Create Alert if string from list appears on other list
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
So....

Need to create an alert that will check a log file if a string appears from a list of strings.

I have a list of words, I want my python program to monitor a log file. If any of the words appear to print the line from the log file.

Been pulling my hair out, little left. Please help.

Any advice, would be appreciated but please god no please spare me the "try googling it" responses...

Thank you in advance..
Use a combination of generator expression and any.

list_of_words = ['A1', 'A2', 'A3']
for line in your_log:
    if any(word in line for word in list_of_words):
        print('ALTERT!')
        print(line)