In your code example, it looks like you are looking for an element in a file, not just a line. Despite this, you can do something similar, which illustrates the execution as with the built-in any() function:
def check_string(text, word_list): return any(phrase in text for phrase in word_list) def check_file(filename, word_list): with open(filename) as some_file: return any(check_string(line, word_list) for line in some_file) black_list = ["ab:", "cd:", "ef:", "gh:"] print check_file('some_file.txt', black_list)
source share