On 30.09.2015 23:33, Andrew Barnert via Python-ideas wrote:
But you're conflating the concept of "lazy" with the concept of "iterator". While generators, and iterators in general, are always technically lazy and nearly-always practically lazy, lazy things are not always iterators. Range, dict views, memoryview/buffer objects, NumPy slices, third-party lazy-list types, etc. are not generators, nor are they like generators in any way, except for being lazy. They're lazy sequences (well, except for the ones that aren't sequences, but they're still lazy containers, or lazy non-iterator iterables if you want to stick to terms in the glossary).
And I think experienced developers conflating the two orthogonal concepts is part of what leads to novices getting confused. They think that if they want laziness, they need a generator. That makes them unable to even form the notion that what they really want is a view/lazy container/virtual container even when that's what they want.
And it makes it hard to discuss issues like this thread clearly.
(The fact that we don't have a term for "non-iterator iterable", and that experienced users and even the documentation sometimes use the term "sequence" for that, only makes things worse. For example, a dict_keys is not a sequence in any useful sense, but the glossary says it is, because there is no word for what it wants to say.)
I have absolutely no idea what you are talking about here. ;)
I have to admit I try to avoid thinking too much about such tiny little details by using generators/lists/sequences/iterables/iterators/did-I-miss-one? directly in for loops only. Thus, the differences between all of them go away pretty fast.
But honestly, does it really need to be that complicated?