I have been trying to optimise this, but since each if has its own condition, i am not able to reduce its complexity
for () in ():
if ():
if ():
#Logical condition
if ():
#Logical condition
else:
#Logical condition
#another condition
if ():
if ():
if ():
#Logical condition
if index in ():
#Logical condition
Edo Akse
4,4052 gold badges13 silver badges25 bronze badges
1 Answer 1
Logic operators are your friend. and, or, xor, etc
for () in ():
if () and ():
#Logical condition
if ():
#Logical condition
pass
else:
#Logical condition
pass
#another condition
if () and () and () and index in ():
#Logical condition
pass
answered Jul 15, 2021 at 12:57
Edo Akse
4,4052 gold badges13 silver badges25 bronze badges
Sign up to request clarification or add additional context in comments.
3 Comments
Pearl
Hello! Thank you for Answering. While adding the next condition, there are two logical conditions I need to add... just let me know how to add the second one as well. Thanks again!
Edo Akse
which next condition are you talking about? It's not exactly clear from how you describe it. That being said, if you have 2 conditions that both need to be met, you would use
if condition1 == True and condition2 == TruePearl
I tried your method but the execution time for 1000 data has increased from 65 seconds to 72 seconds which is undesired. Do let me know the alternatives
lang-py
ifin a row should be combined with&.if cond1: if cond2: if cond3is the same asif cond1 & cond2 & cond3: