Without importing anything, nor numpyany operator.ior, as suggested in the other answers:
a = [1,17,1]
reduce(lambda x,y: x | y, a)
Edit: However, when I was comparing various options, it was faster:
a = [1,17,1]; b = 0
for x in a: b |= x
This second option also has the advantage that it works in Python 3, from which reduceit was eliminated (although it can still be imported from functools).
source
share