PEP 308: A PEP Writer's Experience - PRO

Alex Martelli aleax at aleax.it
Sun Feb 9 12:25:16 EST 2003


Andrew Koenig wrote:

> Samuele> As you might know the "cutest" (my take) general solution to
> Samuele> the problem in current Python (performance aside), has been
> Samuele> posted by Gerald S. Williams to python-dev:
> 
> Samuele> ife = lambda box: box[0]
> 
> Samuele> z = ife(cond and [x] or [y])
> 
> Samuele> if Python had had a ternary cond op, I would never have seen
> Samuele> that <sniff>.
> 
> You're right -- that's about the nicest workaround I've seen.
> 
> But I think I can improve it a tiny bit:
> 
>         ife = list.pop
> 
> Shorter and faster, yes?

Yes (though it's hard to measure the speedup;-).  But definitely
Neat-o, anyway!


Alex





More information about the Python-list mailing list