- 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: Google [Bot], Yahoo [Bot] and 6 guests