- Code: Select all
lambda x : x if x >= 2 else 2
I thought there might be a way to do this as an expression using nothing but arithmetic operators, or at most divmod.
lambda x : x if x >= 2 else 2
max(x, n) --> (x if x >= n else n) --> floor
min(x, n) --> (x if x <= n else n) --> ceiling
min(max(x, a), b) --> x if a <= x <= b else a if x < a else b --> floor and ceiling
min(max(x, a), b)
Users browsing this forum: No registered users and 10 guests