No, because this is not what works and
in python. Firstly, these are not and
list items separately. Secondly, the and
operator works between two objects, and if one of them is False ( evaluated as False 1 ), it returns, and if both are True, then returns the second. Here is an example:
>>> [] and [False] [] >>> >>> [False] and [] [] >>> [False] and [True] [True]
x and y
: if x
false, then x
, else y
If you want to apply logical operations to all pairs of lists, you can use numpy arrays:
>>> import numpy as np >>> a = np.array([True, False]) >>> b = np.array([True, True]) >>> >>> np.logical_and(a,b) array([ True, False], dtype=bool) >>> np.logical_and(b,a) array([ True, False], dtype=bool)
<sub> 1. Here, since you are dealing with lists, an empty list will be evaluated as False Sub>
source share