Parsing of list of bits in python
<p>I have a list of 64 bits.</p>

<pre><code>['11111111', '11111111', '10001111', '11111110', '11011011', '11111111', '01011011', '10000111']
</code></pre>

<p>Here each and every bit represents a feature. If a bit is 1 then that particular feature is supported else not.</p>

<p>Is there any way were i can check the bit and just return its associated feature if it is 1.</p>

<p><code>Input : 1111111</code></p>

<p><code>Output: If all bits are one then I need to print all eight features masked in it.</code></p>

<p>You can make a list of features first.</p>

<pre><code>feat_list = ['f1','f2','f3','f4','f6','f7','f8']

bit_list = ['11111111', '11111111', '10001111', '11111110', '11011011', '11111111', '01011011', '10000111']
</code></pre>

<p>Then make a function. </p>

<pre><code>def extract_feature(bit_string):
    result = []
    for ind, bit in enumerate(bit_string):
        if bit == '1':
            result.append(feat_list[ind])
    return result
</code></pre>

<p>Then use a loop to get features for each bit string.  </p>

<pre><code>for bit_string in bit_list:
    print extract_feature(bit_string)
</code></pre>

<p>Note that, it is not very efficient, but it is verbose so that a newbie can understand. </p>

python python-2.7