News for hackers. Stuff that matters.
Re:Python’s lambda is broken by glomek on Thursday April 09, 2009 @04:20PM (#555075)
Seems fine to me. If you want the captured variable to be different each time, you need to create a new environment each time. How about this?

    >>> fs = [(lambda x: (lambda n: x + n))(i) for i in range(10)]
    >>> [f(4) for f in fs]
    [4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
    >>>

There are no comments on this comment yet.