sequence multiplied by -1
Yingjie Lan
lanyjie at yahoo.com
Sat Sep 25 09:54:36 EDT 2010
Hi,
>
> 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.
>
Thanks for the insightful remarks. For the rule above,
how about the case to reverse and multiply:
>>> L*-3 #L reversed and repeated three times
v.s.
>>> L[::-1]*3 #L reversed and repeated three times
The first one is simpler (4 chars v.s. 9 chars).
I thought it was also intuitive because if you multiply
a vector by -1, you should get a vector
in the reversed direction. But, intuitiveness depends
on who you are, what you do, etc....
Regards,
Yingjie
More information about the Python-list
mailing list