Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Looping over an array but skipping some of the index

I have the following loop which works when creating an output file. There are n-number of rows and 24 columns and it’s going each row and column to create plots. variable below is from index [3:24]. Now the variable is created somewhere in before this loop in the code that I don’t want to touch. I want to be able to overwrite the variable and not go over some of the indexes from [3:24] such as index 22, 20, 3. How can I implement that below? I tried creating another if statement so that when it reaches index 20 it would break. Anyways my solution doesn’t work so I was hoping to get an answer here. Thanks!

for row in range(len(self.CSVResult)):
    if (abs(self.CSVResult[row][variable-1]) < 1.2E20):
       skipsw = 1
       break

For example, variable is looping from index 3 to 24, once it reaches index 22 it will skip and continue to 21. Then once it reaches index 20 it will skip and reach 19. Until it reach index 3 again and then skip that value too.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Does something like this help?

skip_values = [22, 21, 3]
for row in range(len(self.CSVResult)):
    if variable in skip_values:
        continue
    elif (abs(self.CSVResult[row][variable-1]) < 1.2E20):
        skipsw = 1
        break

If I understood correctly, you want to define some ‘skip values’, where if variable is equal one of those, then it does not do the rest of the code.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading