[Python-Dev] bool(iter([])) changed between 2.3 and 2.4
Guido van Rossum
guido at python.org
Wed Sep 21 02:11:35 CEST 2005
On 9/20/05, Terry Reedy <tjreedy at udel.edu> wrote:
> I presume there were two reasons: internal efficiency of preallocations
> (list(some_it) for example)
This could have been implemented without making the implementation
details public.
> and letting people differentiate iterator with
> something left to return versus nothing, just as we can differentiate
> collections with something versus nothing.
But this is against the very idea of the iterator protocol -- for
general iterators, there may be no way to determine whether there is a
next item without actually producing the item, so the proper approach
is to code with that in mind. When this type of look-ahead is
required, a buffering iterator should be inserted, so that the
algorithm can work with all iterators rather than only with iterators
over built-in containers.
--
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-Dev
mailing list