0

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

Sample Data:

enter image description here

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?

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.