expression form of one-to-many dict?
Alex Martelli
aleaxit at yahoo.com
Tue Dec 21 00:13:29 EST 2004
Mike Meyer <mwm at mired.org> wrote:
> bokr at oz.net (Bengt Richter) writes:
>
> > On Sun, 19 Dec 2004 21:29:27 +0100, "Fredrik Lundh"
<fredrik at pythonware.com> wrote:
> > (or maybe a restricted unquote_arg function for better safety).
> > E.g., double back-tick is a syntax error now, so you could write
> >
> > def ternary(c, ``t, ``f):
> > if c: return eval(t)
> > else: return eval(f)
>
> Actually, I think it would be more pythonic if the indication of
> non-evaluation happened at the function invocation instead of the
> function definition. Having it at the function definition makes it
As in, say, calling
x = ternary(c, lambda:t, lambda:f)
? The 'lambda:' is a (not nice-looking, but...) "indication of
non-evaluation"... or am I misundertanding what you're saying?
Of course, the implementation of ternary could then use 'apply' rather
than 'eval' (or, simply call t() or f() as appropriate, identically;-).
Alex
More information about the Python-list
mailing list