9.1 Enumerating the Cartesian product
The term Cartesian product refers to the idea of enumerating all the possible combinations of elements drawn from the elements of sets.
Mathematically, we might say that the product of two sets, {1,2,3,…,13}×{♣,♢,♡,♠}, has 52 pairs, as follows:
We can produce the preceding results by executing the following commands:
>>> cards = list(product(range(1, 14), ’♣♢♡♠’))
>>> cards[:4]
[(1, ’♣’), (1, ’♢’), (1, ’♡’), (1, ’♠’)]
>>> cards[4:8]
[(2, ’♣’), (2, ’♢’), (2, ’♡’), (2, ’♠’)]
>>> cards[-4:]
[(13, ’♣’), (13, ’♢’), (13, ’♡’), (13, ’♠’)]
The calculation...