How to apply bitwise operator to compare a list of objects
<p>Suppose I have a long list of objects (say, a list of numpy matrices of bool elements) <code>foo = [a, b, c]</code>, that I want to compare with some bitwise operator, to get something like <code>a | b | c</code>.</p>

<p>If I could use this bitwise operation as a function, say a <code>bitwiseor</code> function, I could simply do this with <code>bitwiseor(*foo)</code>.
However, I was not able to find whether the bitwise or can be written in such functional form.</p>

<p>Is there some handy way to handle this kind of problem? Or should I just use a loop to compare all the elements cumulatively?</p>

<p>Using the functional method in <a href="https://docs.python.org/2/library/operator.html#operator.or_" rel="nofollow"><code>operator</code></a> in combination with <a href="https://docs.python.org/2/library/functions.html#reduce" rel="nofollow"><code>reduce</code></a>:</p>

<pre><code>&gt;&gt;&gt; import operator, functools
&gt;&gt;&gt; functools.reduce(operator.or_, [1,2,3])
3
</code></pre>

python bitwise-operators