Possible Duplicate:
Check if multiple strings exist in another string
I am trying to find out if there is a nice and clean way to test for 3 different strings.
Basically I am looping trough a file using a for
loop; then I have to check if it contains 1 of the 3 strings that I have set in a list.
So far I have found the multiple if condition check, but it does not feel like is really elegant and efficient:
for line in file
if "string1" in line or "string2" in line or "string3" in line:
print "found the string"
I was thinking like creating a list that contains string1
, string2
and string3
, and check if any of these is contained in the line, but it doesn't seems that i can just compare the list without explicitly loop trough the list, and in that case I am basically in the same conditions as in the multiple if statement that I wrote above.
Is there any smart way to check against multiple strings without writing long if statements or loop trough the elements of a list?