andmap and ormap

Dan Sommers me at privacy.net
Tue Mar 14 07:31:20 EST 2006


On 14 Mar 2006 04:23:55 -0800,
wkehowski at cox.net wrote:

> Hello,
> Does python have andmap and ormap:

> andmap((lambda t: boolean(t)),L)

> gives True if boolean(t) is True for all t in L and False otherwise?
> And

> ormap((lambda t: boolean(t)),L)

> gives True if boolean(t) is True for some t in L and False otherwise?

import operator
reduce( L, operator.and_ ) # andmap
reduce( L, operator.or_ ) # ormap

> One can use a list comprehension like

[ ... ]

> Is this good enough?

If it works, and works correctly, then it's good enough.

Regards,
Dan

-- 
Dan Sommers
<http://www.tombstonezero.net/dan/>
"I wish people would die in alphabetical order." -- My wife, the genealogist



More information about the Python-list mailing list