Python AND operator on two boolean lists - how?

前端 未结 9 2123
感动是毒
感动是毒 2020-11-28 09:36

I have two boolean lists, e.g.,

x=[True,True,False,False]
y=[True,False,True,False]

I want to AND these lists together, with the expected o

9条回答
  •  眼角桃花
    2020-11-28 10:19

    and is not necessarily a Boolean operator; it returns one of its two arguments, regardless of their type. If the first argument is false-ish (False, numeric zero, or an empty string/container), it returns that argument. Otherwise, it returns the second argument.

    In your case, both x and y are non-empty lists, so the first argument is always true-ish, meaning x and y returns y and y and x returns x.

提交回复
热议问题