Re: Programming challenge: wildcard exclusion in cartesian products

2006-03-18 Thread wkehowski
When I run this I get through ghc I get

C:\Documents and Settings\User\My Documents\wildcardghc
./wc-zielonka.hs
compilation IS NOT required
C:/Languages/ghc/ghc-6.4.1/libHSrts.a(Main.o)(.text+0x1d):Main.c:
undefined refe
rence to `__stginit_ZCMain'
C:/Languages/ghc/ghc-6.4.1/libHSrts.a(Main.o)(.text+0x43):Main.c:
undefined refe
rence to `ZCMain_main_closure'
collect2: ld returned 1 exit status

Unless there's a command line option I'm missing?

-- 
http://mail.python.org/mailman/listinfo/python-list


andmap and ormap

2006-03-14 Thread wkehowski
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

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: andmap and ormap

2006-03-14 Thread wkehowski
The following works perfectly:

import operator

def andmap(b,L):
return reduce(operator.and_, [b(x) for x in L])

def ormap(b,L):
return reduce(operator.or_, [b(x) for x in L]) 

Thanks!

-- 
http://mail.python.org/mailman/listinfo/python-list