Pearl
Pearl

Reputation: 1

How to reduce complexity of my nested if with specific conditions on python

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

Upvotes: 0

Views: 50

Answers (1)

Edo Akse
Edo Akse

Reputation: 4391

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

Upvotes: 1

Related Questions