[Python-ideas] Consider making enumerate a sequence if its argument is a sequence

Random832 random832 at fastmail.com
Thu Oct 1 06:03:50 CEST 2015

Akira Li <4kir4.1i at gmail.com> writes:
>> 3. Cannot accept an iterator (goes through it twice, or permanently
>>    stores a reference to it, etc)
> neither
> *iterable* is an object that you can pass to iter() to get *iterator*.
> An iterable does not guarantee that it yields the same items twice.

True or false?: It is reasonable to write algorithms that iterate twice
over a passed-in iterable, with the expectation that said iterable will
typically be an object (or a view of such an object) which will not be
concurrently modified (e.g. by a different thread or by a side-effect of
a callback) during the execution of the algorithm, but which does not
behave in a useful way when given an iterator, a generator, or any other
kind of iterable which exhibits similar behavior whereby the second and
further attempts to iterate will yield no items.

More information about the Python-ideas mailing list