itertools.product

suggest change

This function lets you iterate over the Cartesian product of iterables.

product(A, B) matches nested iteration over A and then B. product takes a variable number of arguments, so an iterable of those inputs can be unpacked with *.

>>> from itertools import product
>>> numbers = [1, 2, 3, 4]
>>> letters = ['a', 'b', 'c']
>>> for pair in product(numbers, letters):
...     print(pair)
...
(1, 'a')
(1, 'b')
(1, 'c')
(2, 'a')
(2, 'b')
(2, 'c')
(3, 'a')
(3, 'b')
(3, 'c')
(4, 'a')
(4, 'b')
(4, 'c')

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents