Could someone please explain why the following does not achieve the desired output.
I have two list: l1 and l2. I want to check if either value is 1 in each list and return this to a 3rd list l3.
Have [1,1,0,0] [0,0,0,1]
Want [1,1,0,1]
I have figured out how to get the desired output with list comprehension:
desired = [1 if i[0]==1 or i[1]==1 else 0 for i in list(zip(l1, l2))]
But I am still not sure why the alternate method gives the wrong output.
l1 = [1,1,0,0]
l2 = [0,0,0,1]
l3 = l1 or l2
print(l3)
OUTPUT: [1, 1, 0, 0]
Also if you reverse the order, l3 = [l2 or l1] you get a different output. Can someone explain?
Thanks