Raymond Hettinger added the comment:
[flying sheep]
that’s probably the end of this :(
Yes, I think so.
--
resolution: - rejected
status: open - closed
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue24849
flying sheep added the comment:
The *iterable* itself may be reentrant, but the iterator formed
from iter(iterable) is not. So by your previous comment, giving
the iterator form a length is not appropriate.
With the exception of tee, all the functions in itertools return
iterators.
ah,
Changes by Serhiy Storchaka storch...@gmail.com:
--
assignee: - rhettinger
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue24849
___
___
flying sheep added the comment:
Hi, and sorry David, but I think you haven’t understood what I was proposing.
Maybe that was too much text and detail to read at once, while skipping the
relevant details:
Python has iterators and iterables. iterators are non-reentrant iterables: once
they are
flying sheep added the comment:
To elaborate more on my second point (“No reentrant iterables are necessary
here, only iterables with a __len__”)
What i meant here is that inside a call of chain(*iterables), such as
chain(foo, bar, *baz_generator()), the paramter “iterables” is always a
R. David Murray added the comment:
No, I guessed that despite saying some arguments have to be iterated that you
were really talking about arguments that had __len__. That's why I added the
sentence about it not being appropriate even if you only did it when the inputs
had __len__.
But I'll
Steven D'Aprano added the comment:
On Wed, Aug 12, 2015 at 09:23:26PM +, flying sheep wrote:
Python has iterators and iterables. iterators are non-reentrant
iterables: once they are exhausted, they are useless.
Correct.
But there are also iterables that create new, iterators whenever
Raymond Hettinger added the comment:
I had explored this idea previously at some length (no pun intended) but it was
mostly a dead-end. The best we ended-up with has having __length_hint__ to
indicate size to list().
There were several issues some of which at detailed in the comment at
New submission from flying sheep:
Things like progressbars want len() to work on iterated objects.
It’s possible to define __len__ for many of the iterables returned by itertools.
some arguments have to be iterated to find the len(): of course we have to
check if those are reentrant, and
Steven D'Aprano added the comment:
Unfortunately, this fails because there is no way to tell how long an arbitrary
iterable is, or whether it is reentrant or not. Consider:
def gen():
while True:
if random.random() 0.5:
return random.random()
Not only is it not
R. David Murray added the comment:
No, you may not iterate the iterator in order to compute the len, because then
the iterator would be exhausted. In addition, the point of itertools is to
*lazily* do operations on iterables of indefinite length, so to offer __len__
if and only if the
11 matches
Mail list logo