Hello,

On Thu, Jan 29, 2009 at 1:46 AM, martin Campos Pinto
<mcp.st...@gmail.com> wrote:
> I get 0 (which is fine), now when I type
>
> b = [lambda x:i for i in range(2)]
> b[0](0)
>
> I get 1 ... There must be a simple explanation for this but I can't
> figure it out. What's wrong ?

This is caused by the scoping rules for Python's lambdas and list
comprehensions.  See the question and answer here for an explanation:
http://stackoverflow.com/questions/139819/why-results-of-map-and-list-comprehension-are-different

--Mike

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to