Suppose you have and arbitrary group of lists:
A=[True, False, False]
B=[True, True, False]
C=[3,0,0]
Now write something that looks a bit like [itertools.izip][1] but allows a function to be added:
def elements(*iterables, **kwds):
func=kwds.get('func', None)
iterables=map(iter, iterables)
while iterables:
t=tuple(map(next, iterables))
if func is not None:
yield func(t)
else:
yield t
Now add functions that will return the logical result of `F(A[0],B[0],C[0]...)`. For example, these each do the function described:
def ands(elements):
''' logical 'and' for all the elements'''
return all(e for e in elements)
def ors(elements):
''' logical 'or' for all the elements'''
return any(e for e in elements)
def bitand(elements):
''' bitwise 'and' for all the elements'''
return reduce(operator.and_,elements)
Then just call the generator:
print list(elements(A,B,C,func=ands))
# [True, False, False]
Or for you specific example:
print list(elements([True,False],[True,True],func=ands))
# [True, False]
Or just use `all` directly:
print list(elements([True,False],[True,True],func=all))
# [True, False]
[1]: http://docs.python.org/2/library/itertools.html#itertools.izip