On Sat, Jun 18, 2022 at 5:42 PM Rob Cliffe via Python-ideas <
python-ideas@python.org> wrote:

> To me, the natural implementation of slicing on a non-reusable iterator
> (such as a generator) would be that you are not allowed to go backwards
> or even stand still:
>      mygen[42]
>      mygen[42]
> ValueError: Element 42 of iterator has already been used


I agree that indexing an iterator such that it could only go forward feels
like a reasonable and useful feature in python, but I disagree about the
ValueError. To me the above produces two values: the 43rd and 85th elements
produced by mygen. Anything else is a bizarre error waiting to arise at
obscure times. What if this iterator is passed to another function? Used in
a loop? Now this information about what index has been used has to be
carried around and checked on every access.

Regards,
Jeremiah
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/K2CBKLZT76AS6MFYBMU3YCP4BP26P2IP/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to