[issue32172] Add length counter for iterables

2017-12-02 Thread R. David Murray
R. David Murray added the comment: Guido specifically rejected __len__ for iterators when the iteration protocol was designed. This has become a FREQ in recent times (Frequently Rejected Enhancement Request :) The rationale, as I understand it, is that an iterator object should always evalu

[issue32172] Add length counter for iterables

2017-11-29 Thread Steven D'Aprano
Steven D'Aprano added the comment: Not every trivial one-liner needs to be in the standard library. In this case, there are two easy (and obvious) ways to do it: sum(1 for x in iterator) len(list(iterator)) (The first probably saves memory; the second probably is faster.) Given how rare it

[issue32172] Add length counter for iterables

2017-11-29 Thread bugale bugale
New submission from bugale bugale : I have noticed that there is no convenient way in python to get the number of items in a generator. For example: my_iterable = iter(range(1000)) len(my_iterable) # Would not work Of course, something like this would ruin the generator, and it will no lon