Re: Slices by length

2025-10-18 Thread Rob Cliffe via Python-list
On 06/09/2025 17:21, MRAB wrote: On 2025-09-06 13:47, Rob Cliffe via Python-list wrote: I quite often find myself writing expressions of the form       someString[x : x+n] where n is often an int and x may be an int, a variable, or a (possibly complicated) expression. It would be more natural

Re: Slices by length

2025-10-18 Thread Richard Damon
Sent from my iPad > On Oct 7, 2025, at 9:59 PM, Rob Cliffe via Python-list > wrote: > > In fairness, it is already possible to write > s[x:][:n] > which gives the "right" answer if n is non-negative, and is quite readable, > although this is slower than s[x:x+2], at least in tests that I

Re: Slices by length

2025-10-18 Thread MRAB
On 08/10/2025 03:21, Richard Damon wrote: Sent from my iPad On Oct 7, 2025, at 9:59 PM, Rob Cliffe via Python-list wrote: In fairness, it is already possible to write s[x:][:n] which gives the "right" answer if n is non-negative, and is quite readable, although this is slower than s[

Re: Slices by length

2025-10-18 Thread Rob Cliffe via Python-list
On 07/10/2025 20:37, Thomas Passin wrote: On 10/7/2025 2:49 PM, Rob Cliffe via Python-list wrote: On 06/09/2025 17:21, MRAB wrote: On 2025-09-06 13:47, Rob Cliffe via Python-list wrote: I quite often find myself writing expressions of the form       someString[x : x+n] where n is often an

Re: Slices by length

2025-10-18 Thread Thomas Passin
On 10/7/2025 2:49 PM, Rob Cliffe via Python-list wrote: On 06/09/2025 17:21, MRAB wrote: On 2025-09-06 13:47, Rob Cliffe via Python-list wrote: I quite often find myself writing expressions of the form       someString[x : x+n] where n is often an int and x may be an int, a variable, or a (po

Re: Slices by length

2025-10-08 Thread meowxiik via Python-list
> Which brings to mind a possible alternate syntax: s[x::n] This would AFAIK collide with the the x[a:b:c] syntax, which already means something, the c is the size of a step M On 8 October 2025 16:22:46 CEST, [email protected]

Re: Slices by length

2025-09-06 Thread dn via Python-list
On 7/09/25 00:47, Rob Cliffe via Python-list wrote: I quite often find myself writing expressions of the form     someString[x : x+n] where n is often an int and x may be an int, a variable, or a (possibly complicated) expression. 0 A PEP 1 A helper-function eg slice_by_length( input_string

Re: Slices by length

2025-09-06 Thread MRAB
On 2025-09-06 13:47, Rob Cliffe via Python-list wrote: I quite often find myself writing expressions of the form     someString[x : x+n] where n is often an int and x may be an int, a variable, or a (possibly complicated) expression. It would be more natural to be able to specify the slice not

Slices by length

2025-09-06 Thread Rob Cliffe via Python-list
I quite often find myself writing expressions of the form     someString[x : x+n] where n is often an int and x may be an int, a variable, or a (possibly complicated) expression. It would be more natural to be able to specify the slice not by its startpoint and ENDPOINT, but by its startpoint an