Some thougts on cartesian products

Christoph Zwerschke cito at online.de
Sun Jan 22 12:29:45 EST 2006


Alex Martelli wrote:
> Kay Schluehr <kay.schluehr at gmx.net> wrote:
>> range(3)**2
>> But why isn't this interpreted as [0, 1, 4] like it is in Mathematica?
> 
> Since range(3)*2 is [0, 1, 2, 0, 1, 2], it would be horribly, painfully
> inconsistent if **2 was interpreted as "square each item".

Yes. Python does not interpreate the product of a list with a number as 
a scalar product. Otherwise range(3)*2 should be [0, 1, 4] as well.

For doing such things I would use a vector subtype of list.

-- Christoph



More information about the Python-list mailing list