testing array of logicals
Fredrik Lundh
fredrik at pythonware.com
Wed Jul 12 14:30:32 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
your code checks all members, even if the first one's false. that's not
very elegant. here's a better way to do it:
def all(S):
for x in S:
if not x:
return False
return True
print all(logfiles)
if you upgrade to 2.5, you can get rid of the function definition; "all"
is a built-in in 2.5.
also see:
http://www.artima.com/weblogs/viewpost.jsp?thread=98196
</F>
More information about the Python-list
mailing list