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. Oh, OK, I have no problem with that (except shouldn't it be the 43rd and 86th elements?). I guess which interpretation is more useful depends on
On 20/06/2022 17:39, Jeremiah Paige wrote: the use case. Best wishes Rob Cliffe
Regards, Jeremiah