On 25 Sep, 09:22, Yingjie Lan <(E-Mail Removed)> wrote:

> Hi,

>

> I noticed that in python3k, multiplying a sequence by a negative integer is the same as multiplying it by 0, and the result is an empty sequence. It seems to me that there is a more meaningful symantics.

>

> Simply put, a sequence multiplied by -1 can give a reversed sequence.

>

> Then for any sequence "seq", and integer n>0, we can have

>

> "seq * -n" producing "(seq * -1) * n".

>

> Any thoughts?

>

> Yingjie
If [1, 2]*-1 is correct, then, arguably, so should be -[1, 2]

Some answers have invoked mathematics to weigh the value of this

proposal, e.g. likening lists to vectors. But the obvious

mathematical analogy is that the set of all lists forms a monoid under

the operation of concatenation, which (unfortunately?) is performed

with the "+" operator in Python. So it is natural that "*" represents

repeated concatenation.

Now under concatenation, non-empty lists do not have an inverse, i.e.

for any non-empty list l, there does not exist a list l' such that l +

l' == []. So there is no natural interpretation of -l and therefore

of l*-1.

However, by using "+" for list (and string) concatenation, Python

already breaks the mathematical pledge of commutativity that this

operator implies.

--

Arnaud