[Python-ideas] Support multiplication for sets

Jakob Bowyer jkbbwr at gmail.com
Fri Oct 7 12:24:05 CEST 2011


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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20111007/7de6ac27/attachment.html>


More information about the Python-ideas mailing list