[Python-Dev] Adding an rslice() builtin?

Guido van Rossum guido at python.org
Tue Aug 29 15:45:05 CEST 2006


That discussion on py3k is far from finished.

We've also had a similar discussion in the past and ended up with
reversed(), which solves the problem on the other end (using a forward
slice but iterating backwards).

Also, when I saw your subject I thought rslice() was related to
rfind(), so the name is at best questuinable.

Let's drop this until we've got clarity on what Py3k actually will do.

--Guido

On 8/29/06, Nick Coghlan <ncoghlan at iinet.net.au> wrote:
> A discussion on the py3k list reminded me that translating a forward slice
> into a reversed slice is significantly less than obvious to many people. Not
> only do you have to negate the step value and swap the start and stop values,
> but you also need to subtract one from each of the step values, and ensure the
> new start value was actually in the original slice:
>
>    reversed(seq[start:stop:step]) becomes seq[(stop-1)%abs(step):start-1:-step]
>
> An rslice builtin would make the latter version significantly easier to read:
>
>    seq[rslice(start, stop, step)]
>
> Cheers,
> Nick.
>
> --
> Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
> ---------------------------------------------------------------
>              http://www.boredomandlaziness.org
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: http://mail.python.org/mailman/options/python-dev/guido%40python.org
>


-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-Dev mailing list