[Python-ideas] More useful slices

Greg Ewing greg.ewing at canterbury.ac.nz
Sun Feb 1 22:51:23 CET 2015


Todd wrote:
> Although slices and ranges are used for different things and implemented 
> differently, conceptually they are similar: they define an integer 
> sequence with a start, stop, and step size.

They behave differently in some ways, though. Consider:

 >>> list(range(9,-1,-1))
[9, 8, 7, 6, 5, 4, 3, 2, 1, 0]

But:

 >>> x = list(range(10))
 >>> x
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
 >>> x[9:-1:-1]
[]

Would your proposed slice-ranges behave like slices or
ranges in this situation? And how will people remember
which?

-- 
Greg


More information about the Python-ideas mailing list