4 ms·
If it is too tiresome to write one more argument: class window: @staticmethod def __init__(min, max): window.min, window.max =
by rnhmjoj 12y ago
If it is too tiresome to write one more argument:
class window:
@staticmethod
def __init__(min, max):
window.min, window.max = sorted((min, max))
@staticmethod
def __call__(x):
return window.min <= x <= window.max
Or if you are just bored of self:
class window:
@classmethod
def __init__(cls, min, max):
window.min, window.max = sorted((min, max))
@classmethod
def __call__(cls, x):
return window.min <= x <= window.max
But my favorite is:
window = lambda *args: (
lambda (min, max)=sorted(args):
type('', (), dict(min=min,
max=max,
__call__=lambda _, x: min <= x <= max))()
)()