Printing a Chunk Of Words

Gregory Ewing greg.ewing at canterbury.ac.nz
Tue Sep 26 03:42:09 EDT 2017


Ben Bacarisse wrote:
> Think functional!  This is 257 characters:

250 chars, 17 shorter than the text it produces:

a=[];o=[];n=[];A=list.append
for b in range(3,-1,-1):
  x=bool(b>>1);y=bool(b&1);A(a,"%s and %s is %s"%(x,y,x and y));A(o,"%s or %s is 
%s"%(x,y,x or y))
  if x:A(n,"not %s is %s"%(y,not y))
print("    Boolean Operators\n"+"-"*24+"\n"+"\n".join(a+o+n))

-- 
Greg



More information about the Python-list mailing list