[FP] Rewriting name bindings as expressions

Ben Wolfson wolfson at midway.uchicago.edu
Fri May 25 17:48:16 CEST 2001

On Fri, 25 May 2001, Thomas Wouters wrote:

>On Fri, May 25, 2001 at 12:03:44AM -0500, Ben Wolfson wrote:
>> ans = [y(x)+1 for y in (lambda a: a*a,) for x in range(10)]
>Maybe I'm missing the point of this thread, but you can write that as:
>ans = [(lambda a: a*a)(x)+1 for x in range(10)]

I think doing it that way will evaluate the lambda definition ten times,
whereas two-loop way evaluates it only once.  I admit it's still pretty

Barnabas T. Rumjuggler
I had a son once, I ain't got no son today
My son is gone now, my son is gone, oy weh
 -- Joe Frank, "Woman and Bull in a Paint Factory"

More information about the Python-list mailing list