[Python-ideas] Support multiplication for sets

Paul Moore p.f.moore at gmail.com
Fri Oct 7 12:35:54 CEST 2011


On 7 October 2011 11:24, Jakob Bowyer <jkbbwr at gmail.com> wrote:
> Looking at this from a Math background, it seems that it would be nice for
> the set type to support multiplication. This would allow for the
> multiplication of sets to produce Cartesian products giving every single
> permutation. This would make set usage more intuitive for example;
> (assuming python3)
>

itertools.product does what you want already.

>>> a = set((1,2,3))
>>> b = set((4,5,6))
>>> set(itertools.product(a,b))
{(2, 6), (1, 4), (1, 5), (1, 6), (3, 6), (2, 5), (3, 4), (2, 4), (3, 5)}

I don't think an operator form is sufficiently valuable when the
functionality is available and clear enough already.

Paul.



More information about the Python-ideas mailing list