]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Add repeat keyword argument to itertools.product().
authorRaymond Hettinger <python@rcn.com>
Thu, 28 Feb 2008 09:23:48 +0000 (09:23 +0000)
committerRaymond Hettinger <python@rcn.com>
Thu, 28 Feb 2008 09:23:48 +0000 (09:23 +0000)
Doc/library/itertools.rst

index 615532270d6c96e9d5191e2d5315fc95a7146984..d9a2b331e0bbb15a835ccd4ab9a80a5a3d3ec702 100644 (file)
@@ -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: