Hacker Newsnew | comments | show | ask | jobs | submit login

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



Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact

Search: