slicing return iter?

Terry Reedy tjreedy at
Sun Oct 18 00:02:20 CEST 2009

StarWing wrote:

> I had checked it for serval times. maybe it's my inattention :-(. but
> what i could find the nearest thing is itertools.islice. but it can't
> process negative index 

A negative index -n is an abbreviation for len(sequence) - n.
Since iterables in general do not have a length, islice(iterable) cannot
handle the abbreviation. If you pass a sequence to islice, just
un-abbreviate negative indexes.

More information about the Python-list mailing list