On Fri, May 15, 2020 at 7:23 PM Stephen J. Turnbull
Chris Angelico writes:
(Technical note: for the convenience of implementors of 'for', when iter is applied to an iterator, it always returns the iterator itself.)
That's not a mere technical detail - that's actually part of the definition of an iterator, namely that iter(x) is x. That's how you can tell that it's an iterator.
From the point of view of teaching iterators to novices, I think it *is* a technical detail. As has been pointed out, there are languages where iterators are *never* iterable. What's *necessary* to an iterator as a concept is that it have a __next__. Python chooses to define the iterator protocol with __iter__ being the identity for iterators because it makes implementing *for* straightforward.
Fair enough. Doesn't make a lot of difference, though.
I don't like this term "converted".
I refuse to die on that hill. :-) Suggest a better term, I'll happily use it until something even better comes along. Or I'll try to come up with a better one as I think about the documentation issue.
Unfortunately I don't have a really good generic term, but I would be inclined to "get an iterator from" an object rather than "convert" it to an iterator. It's still not a great term, but at least it allows you to think about getting multiple iterators from the same thing, even potentially getting different types of iterator. ChrisA