Checking the boolean value of a collection
Diez B. Roggisch
deets at nospam.web.de
Fri Sep 12 10:44:06 EDT 2008
>> if any(instance.forbitToClose(archivefolder) for instance in
>> self.findActiveOutgoingRegistrationInstances())
>
> Can you clarify where I can find "any"? It seems to me I'm unable to find it...
It's part of python2.5.
If you don't have that, you can write it your own and stuff it into
__builtins__:
>>> def any(iterable):
... for item in iterable:
... if item:
... return True
... return False
...
... __builtins__.any = any
You might also want to add all, the companion of any:
>>> def all(iterable):
... for item in iterable:
... if not item:
... return False
... return True
...
Diez
More information about the Python-list
mailing list