If I need to evaluate multiple conditional statements, is it faster to use a nested series of if
statements or to place all conditions within a single if
statement separated by and
? For example:
x=[True, False, False, True]
y=[0,1,2,3]
for i in list(range(len(x))):
if x[i] and expensive_computation(y[i]):
do_something
if x[i]:
if expensive_computation(y[i]):
do_something
Will the first conditional statement if x[i] and expensive_computation(y[i])
check the Boolean value of expensive_computation(y[i])
if x[i]
is already False?