I have to bear with a Python version < 2.5 (it is 2.4.3 for specifics)
It seems that ternary operators were introduces in Python starting at 2.5. For those who are not familiar, ternary operators in Python >= 2.5 look like this:
def do_ternary(flag):
return "foo" if flag else "bar"
I’d like to know some solutions to emulate this in the early versions of Python. I can for sure do it with if … else, but I’m looking for something more pythonic that I wouldn’t be ashamed to put on some production-level code 🙂
Thanks for the help !
Actually I was looking on the web and found what seems like a really elegant pythonic solution:
What do you think about this one? It looks pretty clean and easy to read in my opinion.