The problem is simple enough. I'm writing a function which returns true if the string contains any of the illegal names.
line is a string.
illegal_names is an iterable.
def has_illegal_item(line, illegal_names):
illegal_items_found = False
for item in illegal_names:
if item in line:
illegal_items_found = True
break
return illegal_items_found
So this works fine, but it seems a bit clumsy and long-winded. Can anyone suggest a neater and more pythonic way to write this? Could I use a list comprehension or regex?