a complement function
Brad Knotwell
knotwell at ix.netcom.com
Sat Aug 19 20:47:52 EDT 2000
Hello all--
I was wondering if there's a clean way to do the following:
def complement(function):
return lambda x,function=function: not apply(function,x)
print complement(lambda x: x == 1)((1,))
print complement(lambda x: x == 1)((2,))
print complement(lambda x,y: x == y)((3,4))
print complement(lambda x,y: x == y)((4,4))
As you can see, it works fine as long as the function is called with
a tuple representing all arguments. What I'd prefer is the more obvious
interface:
print complement(lambda x: x == 1)(1)
print complement(lambda x: x == 1)(2)
print complement(lambda x,y: x == y)(3,4)
print complement(lambda x,y: x == y)(4,4)
FWIW, I suppose the real question would ask if there's any way for
default arguments and variably-sized argument lists to play nicely
together.
TIA.
--Brad
More information about the Python-list
mailing list