[False,True] and [True,True] --> [True, True]?????

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Mon Apr 20 03:17:11 EDT 2009


En Mon, 20 Apr 2009 04:03:28 -0300, bdb112 <boyd.blackwell at gmail.com>  
escribió:

> Is there any obvious reason why
> [False,True] and [True,True]
> gives [True, True]

Yes: short-circuit evaluation.
[False,True] and [True,True] is *not* an element-by-element operation,  
it's a simple expression involving two objects (two lists).
A and B means: check the boolean value of A; if it's false, return A.  
Else, return B.
A non-empty list has a boolean value of true, so the second list is  
returned.

If you want an element-wise operation:
A = [False,True]
B = [True,True]
result = [a and b for a,b in zip(A,B)]
-- 
Gabriel Genellina




More information about the Python-list mailing list