[Python-checkins] r61101 - python/trunk/Doc/library/itertools.rst

raymond.hettinger python-checkins at python.org
Thu Feb 28 10:23:48 CET 2008


Author: raymond.hettinger
Date: Thu Feb 28 10:23:48 2008
New Revision: 61101

Modified:
   python/trunk/Doc/library/itertools.rst
Log:
Add repeat keyword argument to itertools.product().

Modified: python/trunk/Doc/library/itertools.rst
==============================================================================
--- python/trunk/Doc/library/itertools.rst	(original)
+++ python/trunk/Doc/library/itertools.rst	Thu Feb 28 10:23:48 2008
@@ -340,7 +340,7 @@
 
    .. versionadded:: 2.6
 
-.. function:: product(*iterables)
+.. function:: product(*iterables[, repeat])
 
    Cartesian product of input iterables.
 
@@ -353,11 +353,15 @@
    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:


More information about the Python-checkins mailing list