summaryrefslogtreecommitdiffstats
path: root/Doc/ref
diff options
context:
space:
mode:
authorSkip Montanaro <skip@pobox.com>2000-08-12 18:09:51 (GMT)
committerSkip Montanaro <skip@pobox.com>2000-08-12 18:09:51 (GMT)
commit803d6e5451cbf0416bfb252eedba36ff2e354fac (patch)
treee37c0cf52e141c341e6b8a64a5d7e7691313df41 /Doc/ref
parentb16b83534d008d45a2917bd2c4fd65010909dff2 (diff)
downloadcpython-803d6e5451cbf0416bfb252eedba36ff2e354fac.zip
cpython-803d6e5451cbf0416bfb252eedba36ff2e354fac.tar.gz
cpython-803d6e5451cbf0416bfb252eedba36ff2e354fac.tar.bz2
list comprehensions. see
http://sourceforge.net/patch/?func=detailpatch&patch_id=100654&group_id=5470 for details.
Diffstat (limited to 'Doc/ref')
-rw-r--r--Doc/ref/ref5.tex19
1 files changed, 14 insertions, 5 deletions
diff --git a/Doc/ref/ref5.tex b/Doc/ref/ref5.tex
index db98fe4..6b699bc 100644
--- a/Doc/ref/ref5.tex
+++ b/Doc/ref/ref5.tex
@@ -152,13 +152,22 @@ A list display is a possibly empty series of expressions enclosed in
square brackets:
\begin{verbatim}
-list_display: "[" [expression_list] "]"
+list_display: "[" [expression_list [list_iter]] "]"
+list_iter: list_for | list_if
+list_for: "for" expression_list "in" testlist [list_iter]
+list_if: "if" test [list_iter]
\end{verbatim}
-A list display yields a new list object. If it has no expression
-list, the list object has no items. Otherwise, the elements of the
-expression list are evaluated from left to right and inserted in the
-list object in that order.
+A list display yields a new list object. Its contents are specified
+by providing either a list of expressions or a list comprehension.
+When a comma-separated list of expressions is supplied, its elements are
+evaluated from left to right and placed into the list object in that
+order. When a list comprehension is supplied, it consists of a
+single expression followed by one or more "for" or "if" clauses. In this
+case, the elements of the new list are those that would be produced
+by considering each of the "for" or "if" clauses a block, nesting from
+left to right, and evaluating the expression to produce a list element
+each time the innermost block is reached.
\obindex{list}
\indexii{empty}{list}