Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Ordinary Python function have the same behaviour due to Python has lexical scopes but dynamic namespaces.

   >>> def add(n):
   ...     return i + n
   ...
   >>> fs = [add for i in range(10)]
   >>> fs[3](4)
   13
This example works due to list-comprehension leaks `i` binding.

http://stackoverflow.com/questions/139819/why-results-of-map...



Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: