Sequence iterators with __index__

Matimus mccredie at
Wed Jun 25 00:45:42 CEST 2008

On Jun 24, 3:29 pm, schickb <schi... at> wrote:
> I think it would be useful if iterators on sequences had the __index__
> method so that they could be used to slice sequences. I was writing a
> class and wanted to return a list iterator to callers.  I then wanted
> to let callers slice from an iterator's position, but that isn't
> supported without creating a custom iterator class.
> Are there reasons for not supporting this generally? I realize not all
> iterators would have the __index__ method, but that seems ok.
> In Python 3, maybe this could be called a SequenceIterator
> -Brad

Could you post an example of what you are talking about? I'm not
getting it. In any case, the first step is writing a PEP.


More information about the Python-list mailing list