Compressing `x if x else y` statement in Python
There is no way to do this, and that’s intentional. The ternary if is only supposed to be used for trivial cases. If you want to use the result of a computation twice, put it in a temporary variable: value = info.findNext(“b”) value = value if value else “Oompa Loompa” Once you do this, it … Read more