

List comprehensions in Python - helwr
http://www.sacredchao.net/~piman/writing/listcomp.shtml

======
beaumartinez
As he says towards the beginning of his post, _Python 2.4 even adds a new kind
of comprehension based on generators_ ; unless you actually _need_ a list, you
should use _generator expressions_ as they use less memory (namely, as
generators, individual items are lazy-loaded; in lists they are _all_ loaded
into memory)[1][2].

(That said, he also says towards the end: _Don't email me asking for me to
optimize your code for you, [...] that's what the Python profiler is for_.)

[1]
[http://docs.python.org/reference/expressions.html#generator-...](http://docs.python.org/reference/expressions.html#generator-
expressions) [2] <http://www.python.org/dev/peps/pep-0289/>

