I have two lists of zeros and ones. Both lists are of same length. The following is just an example, i am looking for a generic solution for lists of any sizes and with zeros and ones at any index.
l1 = [1,1,0,1,1,1,1]
l2 = [0,0,0,1,0,0,0]
The goal is to use the first list l1
as mask
to create a new list l2_new
from l2
that logicaly OR
merges all elements of indizes where l1
is 1
and adopts elements unchanged where l1
is 0
.
Which would result to:
l2_new = [0,0,1]
Graphical explanation: