summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2008-02-28 09:23:48 (GMT)
committerRaymond Hettinger <python@rcn.com>2008-02-28 09:23:48 (GMT)
commit18750ab2a052f3d7b26b5140744d73186f9fd34f (patch)
treeff39f3b035b851ba6a2f9640e1df75a585ae4590 /Doc
parent69e1309fd4faf7e5e4f74f54678f9648316aae37 (diff)
downloadcpython-18750ab2a052f3d7b26b5140744d73186f9fd34f.zip
cpython-18750ab2a052f3d7b26b5140744d73186f9fd34f.tar.gz
cpython-18750ab2a052f3d7b26b5140744d73186f9fd34f.tar.bz2
Add repeat keyword argument to itertools.product().
Diffstat (limited to 'Doc')
-rw-r--r--Doc/library/itertools.rst10
1 files changed, 7 insertions, 3 deletions
diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst
index 6155322..d9a2b33 100644
--- a/Doc/library/itertools.rst
+++ b/Doc/library/itertools.rst
@@ -340,7 +340,7 @@ loops that truncate the stream.
.. versionadded:: 2.6
-.. function:: product(*iterables)
+.. function:: product(*iterables[, repeat])
Cartesian product of input iterables.
@@ -353,11 +353,15 @@ loops that truncate the stream.
so that if the inputs iterables are sorted, the product tuples are emitted
in sorted order.
+ To compute the product of an iterable with itself, specify the number of
+ repetitions with the optional *repeat* keyword argument. For example,
+ ``product(A, repeat=4)`` means the same as ``product(A, A, A, A)``.
+
Equivalent to the following except that the actual implementation does not
build-up intermediate results in memory::
- def product(*args):
- pools = map(tuple, args)
+ def product(*args, **kwds):
+ pools = map(tuple, args) * kwds.get('repeat', 1)
if pools:
result = [[]]
for pool in pools: