On Tue, Oct 6, 2020 at 10:28 AM Alex Hall <alex.moj...@gmail.com> wrote:
> > if you want to iterate through items N to the end, then how do you do that > without either iterating through the first N and throwing them away, or > making a slice, which copies the rest of the sequence? > > ```python > for i in range(start, stop): > x = lst[i] > process(x) > ``` > well yes, of course. but it's kind of a principle in Python that you don't use indices to iterate through a sequence :-) And I still like the sequence view idea, because then the creating of the "subview" could be done outside the iteration code, which would not have to know that it was working with a sequence, rather than any arbitrary iterable. -CHB > The only problem is that there's slightly more execution in Python-land > than in C-land, but that only matters if `process(x)` does very little and > you're really concerned about performance. I can see how the proposal could > be useful but only in very limited use cases. > that is pretty much the same argument as using islice -- it will iterate through the first N elements, but at C speed ... Which is why I see this as "one more use for a sequence view", rather than enough of a motivator in itself. -CHB -CHB -- Christopher Barker, PhD Python Language Consulting - Teaching - Scientific Software Development - Desktop GUI and Web Development - wxPython, numpy, scipy, Cython
_______________________________________________ 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/EWDIJRNYKHA4AXDIW4DICAUJ5MY2C3KP/ Code of Conduct: http://python.org/psf/codeofconduct/