Using the itertools product function in Python
Creating Cartesian products
In combinatorial maths, the Cartesian product takes two sets of values and creates a complete list of every possible pair of values, one from each set. For example, a set of colours combined with a set of shapes creates this Cartesian product:
The Python itertools module provides a function product that performs the same job in Python code. See this article for details.
The article describes what a Cartesian product is, how to create one in Python, use of more than two sets, the repeat parameter, and more.
See PythonInformer for more articles on Python.
Also see this article on graphicmaths.com for more details on Cartesian products.
If you are new to Python, check out our book Python Quick Start.

