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

Nick Coghlan ncoghlan at gmail.com
Tue Aug 29 16:54:40 CEST 2006


Greg Ewing wrote:
> Nick Coghlan wrote:
> 
>>    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)]
> 
> How would this deal with omitted start and/or stop values?

Badly! (negative indices are screwed, too)

This would be an awful lot easier if we could just subclass slice, and do the 
calculation in the indices() method where we have access to len(seq) in order 
to deal with an omitted stop value and negative indices.

Ah well, never mind. I'll take it back to the Py3k list, and see if I can find 
some small changes we can make so that slice() doesn't feel like a bolted-on 
hack that exists solely to avoid the need for a new special method :)

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://www.boredomandlaziness.org


More information about the Python-Dev mailing list