Inverting a conditional function
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Sat Jun 9 05:54:13 EDT 2018
I frequently have a function which tests some condition, returning True
or False, and want a function which reverses the condition.
If all I wanted was the result of calling the function, I could say
not condition(x)
and be done with it, but I want a new function. I've been doing this:
lambda arg: not condition(arg)
which is okay, but its a bit long and adds the cost of an extra function
call. Is there a better way?
--
Steven D'Aprano
"Ever since I learned about confirmation bias, I've been seeing
it everywhere." -- Jon Ronson
More information about the Python-list
mailing list