Checking the boolean value of a collection

Diez B. Roggisch deets at
Fri Sep 12 16:44:06 CEST 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 

 >>> 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


More information about the Python-list mailing list