Is there a way to convert this:
if counts:
def a(l):
return a_with_counts(l)
else:
def a(l):
return a_without_counts(l)
into a ternary expression?
I tried something like this
def a(l):
return a_with_counts(l) if counts else a_without_counts(l)
but I do not want the if counts
to be evaluated each time I call a(l)
, I want to do it once in the beginning of my method and then evaluate directly the assigned function each time I call a(l)
. Is this possible?
Thank you!