testing array of logicals
Gary Herron
gherron at islandtraining.com
Wed Jul 12 14:41:18 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
>
> --
> Thanks,
>
>
The builtin "reduce" does that kind of thing for any function you wish
to apply across the list. So then its only a matter of giving it a
function that "and"s two arguments:
Either:
reduce(lambda a,b: a and b, logFlags)
or
def and2(a,b):
return a and b
reduce(and2, logFlags)
Gary Herron
More information about the Python-list
mailing list