Could you talk more about “BTW: perl is much better than python on this.”?
$variable = something() if sanity_check()
And do_something() unless $dont_do_thatfoo = something() if sanity_check else None
Can replace None with foo (or any other expression), if desired.
variable = something() if sanity_check() else None
do_something() if not dont_do_that else Noneif sanity_check(): variable = something()
variable = sanity_check() and something
(but the standard python two line way is more readable unless it's a throwaway single use code, then whatever)