If this is your entire function, you can just break it into two pieces:
return result = var.get_result()
def funcWithOpt(var, opt):
var = var.set_opt(opt)
result = var.get_result()
return [r for r in result]
If it's longer, you can use subfunctions for the different parts.
However, you should begin with asking yourself if this is a problem at all. Performance is not an issue, checking if
opt exists is inexpensive. If you have a boolean function you need to check, you can just call that function once and 'cache' it in a variable. The function might be slightly longer with this double
if statement, but it's readable and that definitely counts for something.