sequence multiplied by -1

Stefan Schwarzer sschwarzer at sschwarzer.net
Sat Sep 25 09:19:27 EDT 2010


Hi,
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. :)
 L[::-1]
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.
Stefan


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /