[issue24849] Add __len__ to map, everything in itertools

2015-08-14 Thread Raymond Hettinger
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

[issue24849] Add __len__ to map, everything in itertools

2015-08-13 Thread flying sheep
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,

[issue24849] Add __len__ to map, everything in itertools

2015-08-12 Thread Serhiy Storchaka
Changes by Serhiy Storchaka storch...@gmail.com: -- assignee: - rhettinger ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue24849 ___ ___

[issue24849] Add __len__ to map, everything in itertools

2015-08-12 Thread flying sheep
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

[issue24849] Add __len__ to map, everything in itertools

2015-08-12 Thread flying sheep
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

[issue24849] Add __len__ to map, everything in itertools

2015-08-12 Thread R. David Murray
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

[issue24849] Add __len__ to map, everything in itertools

2015-08-12 Thread Steven D'Aprano
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

[issue24849] Add __len__ to map, everything in itertools

2015-08-12 Thread Raymond Hettinger
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

[issue24849] Add __len__ to map, everything in itertools

2015-08-12 Thread flying sheep
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

[issue24849] Add __len__ to map, everything in itertools

2015-08-12 Thread Steven D'Aprano
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

[issue24849] Add __len__ to map, everything in itertools

2015-08-12 Thread R. David Murray
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