This question is similar to here, but I forgot one detail to it.
I want to combine different functions with non-None parameters with and. Suppose I have this function: def foo(a,b,c)
. For every non-None parameter, I want to call a different function and linked with and. But if all of the parameters are None, it must return True
. **The functions will return boolean and are already defined with the respecting parameters. ** For example, let the functions associated with a is bar_1
, b is bar_2
and c is bar_3
. Then the result will be having 7 combinations like this:
if a is not None and b is not None and c is not None:
return bar_1(a) and bar_2(b) and bar_3(c)
elif a is None and b is not None and c is not None:
return bar_2(b) and bar_3(c)
elif a is not None and b is None and c is not None:
return bar_1(a) and bar_3(c)
elif a is not None and b is not None and c is None:
return bar_1(a) and bar_2(b)
elif a is None and b is None and c is not None:
return bar_3(c)
elif a is None and b is not None and c is None:
return bar_2(b)
elif a is not None and b is None and c is None:
return bar_1(a)
else:
return True
How do I do this without listing all of the possible combinations of parameters? For example, is it possible to do something like this? (+= symbolizes and)
func = ...
if a is not None:
func += bar_1(a)
if b is not None:
func += bar_2(b)
if c is not None:
func += bar_3(c)
if all of them wrong:
return True
else:
do func