Proposed PEP for a Conditional Expression

sebastien s.keim at laposte.net
Mon Sep 17 04:38:47 EDT 2001


What do you think about this idiom?

>>> a=5; b=2
>>> c=5*[2,3][a==b]
>>> c
10
>>> a=2
>>> c=5*[2,3][a==b]
>>> c
15

Of course it doesn't solve the PEP problem's:
>>> def toto(x):
...   print "toto"
...   return x+1
... 
>>> c=5*[toto(2),toto(3)][a==b]
toto
toto

But for const expressions, do you think it's obfucassed Python?



More information about the Python-list mailing list