Some thougts on cartesian products

Kay Schluehr kay.schluehr at gmx.net
Sun Jan 22 10:35:29 EST 2006


Giovanni Bajo wrote:
> Christoph Zwerschke wrote:
>
> > Sometimes I was missing such a feature.
> > What I expect as the result is the "cartesian product" of the strings.
>
> I've been thinking of it as well. I'd like it for lists too:
>
> >> range(3)**2
> [(0,0), (0,1), (0,2), (1,0), (1,1), (1,2), (2,0), (2,1), (2,2)]
>
> --
> Giovanni Bajo

But why isn't this interpreted as [0, 1, 4] like it is in Mathematica?

I would prefer a polymorphic distribute(*args) function ( or generator
) that acts on tuples of listlike objects of equal size. It could be
extended to distribute(*args[,default]) by a single default argument
that is inserted in the distribution table when two listlike objects
have not the same size. 

Kay




More information about the Python-list mailing list