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,
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?
--
Greg
On 8/29/06, Greg Ewing [EMAIL PROTECTED] 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
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
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
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
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