sequence multiplied by -1

Stefan Schwarzer sschwarzer at
Sat Sep 25 15:19:27 CEST 2010


On 2010-09-25 14:11, Yingjie Lan wrote:
> Having more than one way of doing things sometimes is good.

In my opinion this _isn't_ a situation where it's good. :)


is only marginally longer than

    -1 * L

I think this small gain doesn't justify "violating" this
"Python Zen" rule (from `import this`):

    There should be one-- and preferably only one --obvious way to do it.

One could argue that using L[::-1] isn't "obvious" but I
believe the rule refers to being obvious to people who have
used Python for a while. Besides that, multiplying a list
with a negative value to give a reverse list isn't so
intuitive either. :-)

On 2010-09-25 13:45, Thomas Jollans wrote:
> Multiplying a list by a negative integer should produce a list of negative 
> length, which does not exist. IMHO, the only correct behaviour would be to 
> raise an exception, though one could argue that there are practical benefits 
> for the operation to succeed for any integer operand.

I agree with raising an exception, probably a ValueError.


More information about the Python-list mailing list