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

2006-08-29 Thread Nick Coghlan
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,

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

2006-08-29 Thread Greg Ewing
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

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

2006-08-29 Thread Paul Moore
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

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

2006-08-29 Thread Guido van Rossum
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

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

2006-08-29 Thread Nick Coghlan
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

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

2006-08-29 Thread David Hopwood
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

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

2006-08-29 Thread Jean-Paul Calderone
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