[Python-Dev] Re: Adding any() and all()

Michael Spencer mahs at telcopartners.com
Fri Mar 11 03:22:23 CET 2005


Guido van Rossum wrote:
> See my blog: http://www.artima.com/forums/flat.jsp?forum=106&thread=98196
> 
> Do we even need a PEP or is there a volunteer who'll add any() and all() for me?
> 

Surely these can be written easily with existing constructs:

def any(S):
     return reduce(lambda x, y: bool(x or y), filter(None,S), False))

def all(S):
     return reduce(lambda x, y: x and y, map(bool, S), True)

;-)

Michael




More information about the Python-list mailing list