Some thougts on cartesian products

Christoph Zwerschke cito at
Mon Jan 23 17:41:41 CET 2006

Bryan Olson schrieb:
> Christoph Zwerschke wrote:
> [...]
>> That may be the main problem to decide whether the cartesian product 
>> should return a generator or a list.
> The Cartesion product is a set.

Of course it is a set. But if the factors of the product have a total 
order (as in the case of strings, tuples or lists), this carries over to 
the cartesian product (lexicographical order). The implementation should 
reflect that by giving you a list or a generator, not a set.

Only if I build the cartesian product of sets I would expect a set.

"ab"*"cd" should be "ac", "ad", "bc", "bd", in this order.

> Cartesian product is one of the essential operations of
> relational algebra; in that context it's widely useful.
> By itself, it's usually not what one wants.

Usually not. But sometimes you may want it. That's why SQL defines has 
the "cross join" clause. Usually it is not needed and should be avoided, 
but sometimes it may make sense.

-- Christoph

More information about the Python-list mailing list