andmap and ormap

wkehowski at cox.net wkehowski at cox.net
Tue Mar 14 13:23:55 CET 2006


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?
One can use a list comprehension like

[x for x in L if not(False in map((lambda t: boolean(t)),L))]

as an example of selection by andmap, and

[x for x in L if (True in map((lambda t: boolean(t)),L))]

as an example of selection by ormap.

How does one define andmap/ormap so its first argument is a boolean
procedure or lambda?

def andmap(b,L):
  if False in map(b,L): return False
  else: return True

def ormap(b,L):
  if True in map(b,L): return True
  else: return False

Is this good enough?

Walter Kehowski




More information about the Python-list mailing list