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>I don't know whether I've understood exactly :)</p>

<pre><code>def extract_features(x, f):
    return [f[i] for i, elem in enumerate(x) if x[i] == '1']


features = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']
x = '11111111'    
y = '10101010'

print (extract_features(x, features))
print (extract_features(y, features))

"""
&lt;Output&gt;
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']
['a', 'c', 'e', 'g']
"""
</code></pre>

python python-2.7