here is the code:
(lambda a,b,c,d,operator: ((lambda a,b,c:((c) if (a == b)))(a,b,c)) if (operator == "aebc") else (((lambda a,b,c:((c) if (a != b)))(a,b,c)) if (operator == "anebc") else (((lambda a,b,c:((c) if (a <= b)))(a,b,c)) if (operator == "alebc") else (((lambda a,b,c:((c) if (a < b)))(a,b,c)) if (operator == "albc") else (((lambda a,b,c:((c) if (a >= b)))(a,b,c)) if (operator == "agebc") else (((lambda a,b,c:((c) if (a > b)))(a,b,c)) if (operator == "agbc") else (((lambda a,b,c,d:((c) if (a == b) else (d)))(a,b,c,d)) if (operator == "aebced") else (((lambda a,b,c,d:((c) if (a != b) else (d)))(a,b,c,d)) if (operator == "anebced") else (((lambda a,b,c,d:((c) if (a <= b) else (d)))(a,b,c,d)) if (operator == "alebced") else (((lambda a,b,c,d:((c) if (a < b) else (d)))(a,b,c,d)) if (operator == "albced") else (((lambda a,b,c,d:((c) if (a >= b) else (d)))(a,b,c,d)) if (operator == "agebced") else (((lambda a,b,c,d:((c) if (a > b) else (d)))(a,b,c,d)) if (operator == "agbced")))))))))))))()
I’m making a one-liner for "easy" if statements, to be used in other one-liners. However, I am getting multiple invalid syntax errors. How might I fix this, or is there a fundamental problem with this code?
>Solution :
Looks heavy, why not use regular functions?
At first glance, one of the problems is the incorrect use of the ternary operator.
You need use this:
c if a == b else some_value
Use it so wrong:
c if a == b