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

counting 1's in a bit string to keep positions in a variable and then accessing each value

I am finding 1’s in a bit string and then storing them.

Sample Data:

enter image description here

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

Sample code:

def indices(chromosome):
    return {i for i,c in enumerate(chromosome) if c=='1'}

for ind in df_initial_pop['initial_pop'].index:
    locations = indices(df_initial_pop['initial_pop'] [ind])
    print (locations)

Output:

{32, 29, 31}
{8, 34, 23}
{34, 35, 31}
{17, 14, 31}
{26, 19, 34}

Now, I want to access 32, 29, and 31 and store each of them in a separate variable. Is it possible?

>Solution :

Sure it is possible, but using individual variables implies that the number of elements in your set is fixed.

s = {32, 29, 31}
a,b,c = s
# Now a=32, b=29, c=31
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