[Python-ideas] Where did we go wrong with negative stride?
Paul Moore
p.f.moore at gmail.com
Tue Oct 29 11:23:24 CET 2013
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 :-(
Paul
More information about the Python-ideas
mailing list