testing array of logicals
Stefan Behnel
stefan.behnel-n05pAM at web.de
Wed Jul 12 14:29:00 EDT 2006
John Henry wrote:
> 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
Py2.5:
test = all( logflags )
Py2.4 (although somewhat ugly):
try:
test = itertools.ifilterfalse( logflags ).next()
except StopIteration:
test = True
otherwise: your above code will do just fine. Note that you can shortcut,
though, if any of the flags evaluates to False:
test = True
for x in logflags:
if not x:
test = False
break
Stefan
More information about the Python-list
mailing list