On Tue, 29 Aug 2006 17:44:40 +0100, David Hopwood <[EMAIL PROTECTED]> wrote:
>Nick Coghlan 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)]
>
>Or slice.reversed().
>

Better, slice.reversed(length).

Jean-Paul
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to