Loop in list.
Fredrik Lundh
fredrik at pythonware.com
Tue Feb 8 09:58:18 EST 2005
"Jim" <jtp11 at att.net> wrote:
> Where did this type of structure come from:
>
> mat = ['a' for i in range(3)] ?
>
> This will produce a list of three elements but
> I don't see reference for it in any of the books.
it's called "list comprehension", and was added in Python 2.0.
http://www.amk.ca/python/2.0/index.html#SECTION000600000000000000000
http://docs.python.org/tut/node7.html#SECTION007140000000000000000
http://docs.python.org/ref/lists.html
Python 2.4 introduces a variation called "generator expressions":
http://www.python.org/doc/2.4/whatsnew/node4.html
http://www.python.org/peps/pep-0289.html
http://docs.python.org/ref/genexpr.html
</F>
More information about the Python-list
mailing list