[issue21744] itertools.islice() goes over all the pre-initial elements even if the iterable can seek

2014-06-13 Thread Josh Rosenberg
Changes by Josh Rosenberg shadowranger+pyt...@gmail.com: -- nosy: +josh.rosenberg ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue21744 ___ ___

[issue21744] itertools.islice() goes over all the pre-initial elements even if the iterable can seek

2014-06-13 Thread R. David Murray
R. David Murray added the comment: Then don't use itertools for that case. itertools is designed for working with *arbitrary* iterables, and arbitrary iterables are not seekable. I'll leave it to Raymond to decide if it is worth making a special-case optimization :) -- nosy:

[issue21744] itertools.islice() goes over all the pre-initial elements even if the iterable can seek

2014-06-13 Thread Josh Rosenberg
Josh Rosenberg added the comment: I would think that allowing the special case optimization would be a good idea. As is, if you want to take slices of buffers without making copies, you can use memoryview and get O(1) views of a slice of the memory. But there's nothing built-in that's even

[issue21744] itertools.islice() goes over all the pre-initial elements even if the iterable can seek

2014-06-13 Thread Josh Rosenberg
Josh Rosenberg added the comment: I will admit, on further consideration, a dedicated sequenceview might work more nicely. islice's interface is limited by its generality; since it doesn't assume a length, you can't use a negative value for end. Does anyone think a general sequenceview class

[issue21744] itertools.islice() goes over all the pre-initial elements even if the iterable can seek

2014-06-13 Thread Raymond Hettinger
Raymond Hettinger added the comment: I'll leave it to Raymond to decide if it is worth making a special-case optimization :) Special cases aren't special enough ... :-) The itertools are specifically designed to work with general iterators, not just sequences. Does anyone think a

[issue21744] itertools.islice() goes over all the pre-initial elements even if the iterable can seek

2014-06-12 Thread Jesús Cea Avión
New submission from Jesús Cea Avión: If L is a big sequence and I do itertool.islice(L, 100, None), islice will go over a million elements before returning the first that I actually cared. Since L is a sequence, islice could go directly to the element 100. My program performance