summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2008-02-22 19:50:06 (GMT)
committerRaymond Hettinger <python@rcn.com>2008-02-22 19:50:06 (GMT)
commitc5705a823bb200b48417677f8ef3ca6833ace4bb (patch)
treeec0c9ad87f58c31fc2ef6a34c879705bfe11e38a /Doc
parentfb0742fe4f5d07b21764479c3c90ce6c4e1e256f (diff)
downloadcpython-c5705a823bb200b48417677f8ef3ca6833ace4bb.zip
cpython-c5705a823bb200b48417677f8ef3ca6833ace4bb.tar.gz
cpython-c5705a823bb200b48417677f8ef3ca6833ace4bb.tar.bz2
Document itertools.product().
Diffstat (limited to 'Doc')
-rw-r--r--Doc/library/itertools.rst23
1 files changed, 23 insertions, 0 deletions
diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst
index d8faba7..7d1ec96 100644
--- a/Doc/library/itertools.rst
+++ b/Doc/library/itertools.rst
@@ -302,6 +302,29 @@ loops that truncate the stream.
.. versionadded:: 2.6
+.. function:: product(*iterables)
+
+ Cartesian product of input iterables.
+
+ Equivalent to nested for-loops in a generator expression. For example,
+ ``product(A, B)`` returns the same as ``((x,y) for x in A for y in B)``.
+
+ The leftmost iterators are in the outermost for-loop, so the output tuples
+ cycle in a manner similar to an odometer (with the rightmost element
+ changing on every iteration).
+
+ Equivalent to (but without building the entire result in memory)::
+
+ def product(*args):
+ pools = map(tuple, args)
+ if pools:
+ result = [[]]
+ for pool in pools:
+ result = [x+[y] for x in result for y in pool]
+ for prod in result:
+ yield tuple(prod)
+
+ .. versionadded:: 2.6
.. function:: repeat(object[, times])