paddy3118@netscape.net wrote:
[color=blue]
> I actually have a set of lambdas so my use will be more like:[/color]
A set of lambdas gains you nothing.
[color=blue][color=green][color=darkred]
>>> (lambda: a > 0) in set([lambda: a > 0])[/color][/color][/color]
False
is probably not what you expected. So you might want to go back to strings
containing expressions. Anyway, here is a way to "and" an arbitrary number
of functions (they all must take the same arguments):
[color=blue][color=green][color=darkred]
>>> def make_and(*functions):[/color][/color][/color]
.... def all_true(*args, **kw):
.... for f in functions:
.... if not f(*args, **kw):
.... return False
.... return True
.... return all_true
....[color=blue][color=green][color=darkred]
>>> abc = make_and(lambda: a > 0, lambda: b < 0, lambda: c == 0)
>>> a, b, c = 1, -1, 0
>>> abc()[/color][/color][/color]
True[color=blue][color=green][color=darkred]
>>> c = 1
>>> abc()[/color][/color][/color]
False
For a set/list of lambdas/functions, you would call make_and() with a
preceding star:
and_all = make_and(*some_set_of_functions)
[color=blue]
> - Gosh, isn't life fun![/color]
I seem to remember that the manual clearly states otherwise :-)
Peter