[Python-ideas] Support multiplication for sets

Amaury Forgeot d'Arc amauryfa at gmail.com
Fri Oct 7 17:36:20 CEST 2011


2011/10/7 Jakob Bowyer <jkbbwr at gmail.com>:
> 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)
>
> a = set(["amy", "martin"])
> b = set(["smith", "jones", "john"])
> c = a * b
> print(c)
> set([('john', 'jones'),
>      ('john', 'martin'),
>      ('jones', 'john'),
>      ('martin', 'amy'),
>      ....])

Is your example correct? It does not look like a cartesian product to me.
and what about writing it this way:
    {(x,y) for x in a for y in b}


-- 
Amaury Forgeot d'Arc



More information about the Python-ideas mailing list