[Python-ideas] Support multiplication for sets

Mike Graham mikegraham at gmail.com
Fri Oct 7 19:08:12 CEST 2011


On Fri, Oct 7, 2011 at 6:24 AM, 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)
>
> a = set(["amy", "martin"])
> b = set(["smith", "jones", "john"])
> c = a * b
> print(c)
>
> set([('john', 'jones'),
>      ('john', 'martin'),
>      ('jones', 'john'),
>      ('martin', 'amy'),
>      ....])
>
> This could be really easily achieved by giving a __mul__ method for sets.
> Currently trying to multiply sets gives a TypeError. Anyone got any views on
> this? Or am I barking up the wrong tree and saying something stupid.
>
>
This idea might be aesthetically pleasing from a mathematical viewpoint, but
it does not help people write better programs. It does not provide anything
better than the status quo. In fact, it adds an obscure behavior that needs
to be maintained, taught, and understood, making Python ever-so-slightly
worse.

-1

Mike
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20111007/efae8e3b/attachment.html>


More information about the Python-ideas mailing list