For review: PEP 308 - If-then-else expression

Evan evan at 4-am.com
Sat Feb 8 20:21:07 EST 2003


Michele Simionato wrote:
> Not convincing. For multiple choices one should use a dictionary. I am favorable
> to a ternary operator but against a "case" operator.

Please explain how the following could be implemented with a dictionary 
(note that f and g have side-effects, and should only be called if we 
need their value):

x = {if a == 1: f(),
         g() == 'asdf': 'g',
         c > 4.5: 'yep'
         'nope'}

A lot of lambdas, perhaps?

Cheers,

Evan @ 4-am





More information about the Python-list mailing list