testing array of logicals

Ant antroy at gmail.com
Wed Jul 12 14:35:50 EDT 2006


John Henry wrote:
> Hi list,
>
> Is there a more elagant way of doing this?
>
> # logflags is an array of logicals
> test=True
> for x in logflags:
>    test = test and x
> print test

There's reduce, but it's not as explicit, and see F's post RE
efficiency:

>>> x = [True, True, True]
>>> y = [True, False, True]
>>> print reduce(lambda a, b: a and b, x)
True
>>> print reduce(lambda a, b: a and b, y)
False
>>>




More information about the Python-list mailing list