Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Lambda if statement problems

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading