I have to check a lot of worlds if they are in string… code looks like:
if "string_1" in var_string or "string_2" in var_string or "string_3" in var_string or "string_n" in var_string:
do_something()
how to make it more readable and more clear?
This is one way:
Reference:
any()Update:
For completeness, if you want to execute the function only if all words are contained in the string, you can use
all()instead ofany().Also note that this construct won’t do any unnecessary computations as
anywill return if it encounters atruevalue and a generator expression is used to create the Boolean values. So you also have some kind of short-circuit evaluation that is normally used when evaluating Boolean expressions.