The problem I'm facing is that I have a list of lists.
a = [[1, 1, 1, 0, 0, 0],
[1, 1, 1, 0, 1, 1],
[1, 0, 0, 1, 0, 0]]
I want to do AND/OR/Majority-voting operations on the elements of the lists inside the list a. I want to get a single list result by, for example, doing an AND operation index by index so it see if elements on index 0 (in the lists) fulfill AND operation criteria so it append 1 to a result list incase all elements on index 0 are 1, else 0.
and_operation_on_a = [1, 0, 0, 0, 0, 0]
def and_op(alist):
result_list = []
for x, y, z in zip(alist[0], alist[1], alist[2]):
if x == 1 and y == 1 and z == 1:
result_list.append(1)
else:
result_list.append(0)
return result_list
I tried something like this as the list has 3 lists inside and it works for me but what I want to do is to generalize it. For example, for the function to do an AND/OR/Majority-voting operation (element-by-element or index-by-index) if given a variable number of lists inside. I shall be really thankful to you If someone can help me. I am stuck badly.