[Tutor] lamda in list comp
Mark Lawrence
breamoreboy at yahoo.co.uk
Mon Mar 30 02:13:24 CEST 2015
On 29/03/2015 02:25, Jim Mooney wrote:
> Shouldn't this give me a list of squares?
> [lambda x: x**2 for x in range(10)]
>
> Instead I'm getting ten of these (with different addresses)
> <function <listcomp>.<lambda> at 0x01262A50>]
>
That's exactly what you've asked the code to do. What makes you think
you need a lambda function?
[x**2 for x in range(10)]
should do the trick.
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
More information about the Tutor
mailing list