mardi 22 juin 2021

How to refactor function with many if statements and for loops? [closed]

I am looking into a function that has a few for loops containing multiple if statements, and if statements only. Barely any else and NO elifs at all. Simplification of the function:

def function():
...
  for value in list:
  ...
    for key in dict:
    ...
    if word1 in something:
      ...
    if word2 in something:
      ...
        if variable:
          ...
    if word3 in something:

As you can see, it is very complex and I want to refactor this function. Some if statements contains other if-statements (nested). Any suggestions? Can i move out the ifs as separate functions instead? Should I use switch-statements?

Aucun commentaire:

Enregistrer un commentaire