[Python-ideas] Consider making enumerate a sequence if its argument is a sequence
4kir4.1i at gmail.com
Thu Oct 1 07:15:25 CEST 2015
Random832 <random832 at fastmail.com> writes:
> 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)
>> *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.
True or false?: do all iterables return the same items twice?
Specific application may use more specific requirements e.g.:
- does it mean that all iterables must be finite?
- do we need a special word to describe what list() accepts?
- does it mean that all iterables must yield hashable items?
- do we need a special word to describe what set() accepts?
- does it mean that all iterables must yield pairs?
- do we need a special word to describe what dict() accepts?
You've got the idea: the word *iterable* may be used in the context when
not all iterables are accepted.
More information about the Python-ideas