PEP 308: Obfuscated Nested Ternaries (INACAIS)

Steven Taschuk staschuk at telusplanet.net
Fri Feb 21 00:56:57 CET 2003


Quoth Gerrit Holl:
> For the Obfuscated Contest: rewrite this peace of code
> using ternaries. Preferably with a lot of ('s and )'s :)

How's this?

        seq = tuple([((tl,t,tr),(l,None,r),(bl,b,br))[y][x]for x,y in
                (lambda x:zip(x[0],x[1]))(map(lambda x,y:map(x==1 and
                (lambda x:2-x)or None,y),map(cmp,(x,y),(0,)*2),((((2,
                0,1,0,0,0),(2,0,0,0,1,0)),((2,0,1,0,1,0),(1,1,0,1,2,1
                ))),(((1,1,0,1,2,1),(2,0,1,0,1,0)),((0,2,2,0,0),(0,0,
                2,2,0))))[x==0][y==0]))])

Only one ternary operator, I'm sorry to say.  Lots of parentheses,
though.

-- 
Steven Taschuk                            staschuk at telusplanet.net
Every public frenzy produces legislation purporting to address it.
                                           (Kinsley's Law)





More information about the Python-list mailing list