[Python-ideas] Where did we go wrong with negative stride?

MRAB python at mrabarnett.plus.com
Tue Oct 29 19:08:00 CET 2013


On 29/10/2013 10:23, Paul Moore wrote:
> On 28 October 2013 22:41, Guido van Rossum <guido at python.org> wrote:
>> I'm not sure I like new syntax. We'd still have to find a way to represent
>> this with slice() and also with range().
>
> It's a shame there isn't an indexing syntax where you can supply an
> iterator that produces the set of indexes you want and returns the
> subsequence - then we could experiment with alternative semantics in
> user code.
>
> So, for example (silly example, because I don't have the time right
> now to define an indexing function that matches any of the proposed
> solutions):
>
>      >>> def PrimeSlice():
>      >>>    yield 2
>      >>>    yield 3
>      >>>    yield 5
>      >>>    yield 7
>
>      >>> 'abcdefgh'[[PrimeSlice()]]
>      'bceg'
>
> But of course, to make this user-definable needs new syntax in the
> first place :-(
>
We already use (...) and [...], which leaves {...}:

 >>> 'abcdefgh'{PrimeSlice()}
'bceg'



More information about the Python-ideas mailing list