On 1 February 2015 at 07:13, Todd <toddrjen@gmail.com> wrote:

For examples, the following pairs are equivalent:

range(4, 10, 2)
(4:10:2)


I think I remember a proposal somewhere to allow slice notation (defining slice objects) outside of [] indexing. That would conflict with this idea of having slice notation define range objects. However, if slice notation defined slice objects and slice objects were iterable, wouldn't that have the same benefits?

Iterating over a slice object would work like you were lazily taking that slice from itertools.count() - i.e. iter(a:b:c) would be equivalent to islice(count(), a, b, c). This would also mean that (3:) would have a logical meaning without having to modify range objects to support an optional upper bound. I don't see any logical way to iterate over a slice defined with negative numbers (e.g. (-4:)), so presumably iter(-4:) would raise an exception.

Thomas