slicing return iter?

Terry Reedy tjreedy at udel.edu
Sat Oct 17 18:02:20 EDT 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