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

A generator expression is an easy way the create a function that performs a small part of the calculation each time it's run (and has memory of the state it's in). Since code often uses a one item at a time, this is less memory intensive then first generating the complete list and storing it in memory.

http://www.python.org/dev/peps/pep-0289/

The generator part in the example is the '(y in [])' the rest is a list comprehension (a short way of writing for loops that can be implemented very efficiently in a language and will return a list).

[UPDATE] Found a better explanation that also explains expression closures at http://ejohn.org/blog/javascript-18-progress/



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

Search: