On 4/1/2016 4:14 PM, Marko Rauhamaa wrote:
There's a bit of a cognitive dissonance between iterables and iterators. On the one hand, they behave identically in many contexts.
Because iterators *are* (a proper subset of) iterables This goes back to pre-iterator days when for-loops worked on sequences and sequence-like objects. When iterators (and generators and generator functions) were added and the iteration protocol added to the sequence protocol, 'sequence' was generalized to 'iterable'. Replacing 'sequence' with 'iterator' (and having an iterator not be an iterable) would have broken most code and made for loops less convenient to use.
On the other hand, the distinction
between iterators and non-iterator iterables
is crucial in some special cases.
I often call non-iterator iterables 're-iterables' (which is usually correct) but there is no agree-on term. It is sort of like having 'people' and 'men' but no word for non-men people.
(Somehow, the difference between iterables and iterators is analogous with the difference between C's arrays and pointers.)
(Yes, C uses pointers to iterates through arrays, in either direction.) -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list