negate()
Return the negation of a predicate function.
Implementation
Args: func: The predicate function to negate Returns: A function that returns the opposite of the original function
Example
def is_even(x):
return x % 2 == 0
negate(is_even)(3)
Expected output: False
Source Code
def negate(func: Callable) -> Callable:
return lambda *args, **kwargs: not func(*args, **kwargs)