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

Greg Ewing greg.ewing at canterbury.ac.nz
Mon Oct 28 00:45:15 CET 2013


Neal Becker wrote:
> One thing I find unfortunate and does trip me up in practice, is that
> if you want to do a whole sequence up to k from the end:
> 
> u[:-k]
> 
> hits a singularity if k=0

I think the only way to really fix this cleanly is to have
a different *syntax* for counting from the end, rather than
trying to guess from the value of the argument. I can't
remember ever needing to write code that switches dynamically
between from-start and from-end indexing, or between
forward and reverse iteration direction -- and if I ever
did, I'd be happy to write two code branches.

-- 
Greg


More information about the Python-ideas mailing list