On Mon, Nov 27, 2017 at 06:53:23PM +0200, Koos Zevenhoven wrote: > Making iterators behave like sequences (slicing etc.) introduces various > issues including memory considerations and backwards compatibility.
Perhaps. I'm not going to actively champion the idea of supporting slicing for iterators, but the idea I had was for no more than having iterator[start:stop:step] to do *exactly* what itertools.islice(iterator, start, stop, step) does now. > That's > why the `views` package [1] keeps a clear separations between sequences and > iterators. IterABLES are a bit fuzzy here, but they at least should be able > to produce an iterator. I don't think the concept of iterable is fuzzy: they are a superset of iterators. To be precise, an iterable is something which supports iteration, which means it must either: - support the iterator protocol with __iter__ and __next__ raising StopIteration; - or support the classic sequence protocol with __getitem__ raising IndexError at the end of the sequence. I think that's the only two possibilities. That covers (all?) collections, sequences, lists, lazy computed sequences like range, iterators, generators, etc. https://docs.python.org/3/glossary.html#term-iterable -- Steve _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/