expression form of one-to-many dict?

Paul Rubin http
Mon Dec 20 23:59:30 EST 2004


Mike Meyer <mwm at mired.org> writes:
> Personally, I'd love a language feature that let you create a function
> that didn't evaluate arguments until they were actually used - lazy
> evaluation. That lets you write the C ?: operator as a function, for
> a start.
> 
> Hmmm. No, iterators can't be used to fake it. Oh well.

You can fake it with lambda, but the syntax is contorted.

    a = condition ? expr1 : expr2;

becomes

    a = ((lambda: expr2, lambda: expr1)[bool(condition)])()



More information about the Python-list mailing list