[FP] Rewriting name bindings as expressions

Ben Wolfson wolfson at uchicago.edu
Fri May 25 01:03:44 EDT 2001


In article <mailman.990765936.620.python-list at python.org>, "Dr. David
Mertz" <mertz at gnosis.cx> wrote:

> Greg Ewing <see at my.signature> wrote:
>> ans = [y+1 for x in range(10) for y in (x*x,)]
> 
> Wow. Richard had written me before posting to the list, and I did not
> have any idea for improving on his examples.  I don't think this form
> would have ever occurred to me... but now that I see it, I am simply
> shocked by its obviousness and clarity.

Another one that doesn't really rebind y is

ans = [y(x)+1 for y in (lambda a: a*a,) for x in range(10)]

-- 
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