boolean operations on sets

Thomas Jollans thomas at jollans.com
Mon Aug 6 11:30:08 EDT 2007


On Monday 06 August 2007, Flavio wrote:
> So My question is: Why has this been implemented in this way? I can
> see this confusing many newbies...

I did not implement this, so I cannot say, but it does have useful 
side-effects, for example:

x = A or B

is equivalent to:

if A:
  x = A
else:
  x = B

also, in python implementations without the (y if x else z) syntax, you can 
use (x and y or z) with nearly the same result*. Also, this implementation of 
and/or might well be faster ;-)


*: this doesn't work the same if y is a false value; (x and [y] or [z])[0] is
   less readable, but works for all y

-- 
      Regards,                       Thomas Jollans
GPG key: 0xF421434B may be found on various keyservers, eg pgp.mit.edu
Hacker key <http://hackerkey.com/>:
v4sw6+8Yhw4/5ln3pr5Ock2ma2u7Lw2Nl7Di2e2t3/4TMb6HOPTen5/6g5OPa1XsMr9p-7/-6
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 196 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.python.org/pipermail/python-list/attachments/20070806/9f47a7e0/attachment.sig>


More information about the Python-list mailing list