On Fri, Jul 26, 2019 at 7:47 AM Greg Ewing
Batuhan Taskaya wrote:
I think it looks very fine when you type {1, 2, 3} * {"a", "b", "c"} and get set(itertools.product({1, 2, 3}, {"a", "b", "c"})). So i am proposing set multiplication implementation as cartesian product.
I'm not sure this would be used frequently enough to justify making it a built-in operation on sets. I can't think of any situation where I've wanted to materialise a Cartesian product as an actual set object. Usually I'm iterating over it and doing something else, and we already have more flexible ways of doing that -- list comprehensions, nested loops, etc.
Also, this would really only work sensibly for Cartesian products of two sets, not three or more. Writing s1 * s2 * s3 wouldn't give you a set of 3-tuples (a, b, c), but a set of 2-tuples ((a, b), c). Mathematicians usually gloss over this distinction, but in programming it becomes important.
Both could be solved if the product of a set and a set was a "Cartesian product" object that just retains an iterator on each. Still not sure how necessary it is, but I'm no mathematician. ChrisA