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

How to make a single list of all the entities of an output of a loop

Below is the code which returns a print out of 8 figures:

for i in range(A,A+30):
        for j in range(6,7):
            if "X" in str(sh1.cell(i,j).value):
                print(i)

Commandline Output:

44
55
57
61
65
69
71
72

How can I store these entities in their order in a single list like this:

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

["44", "55", "57", "61", "65", "69", "71", "72"]

>Solution :

I suppose you want to create a new list and add the items to it:

values = []
for i in range(A,A+30):
    for j in range(6,7):
        if "X" in str(sh1.cell(i,j).value):
            print(i)
            values.append(str(i))

values == ["44", "55", "57", "61", "65", "69", "71", "72"]

Getting familiar with lists (and other basic python data structures) can get very handy: https://docs.python.org/3/tutorial/datastructures.html#more-on-lists

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