Is there a way to do the following in a one-liner:
x = heavy_computation() if heavy_computation() > 0 else None
without heavy_computation()
being called twice? Of course, one could do:
val = heavy_computation()
x = val if val > 0 else None
but I was wondering if there is a more pythonic way to achieve this in one line. This might be useful for heavy computations but also for better code readability.