[Python-ideas] Generator unpacking

Andrew Barnert abarnert at yahoo.com
Tue Feb 16 01:12:55 EST 2016


On Feb 15, 2016, at 21:59, Michael Selik <mike at selik.org> wrote:
> 
> The glossary entry for "iterator" already says, "A container object (such as a list) produces a fresh new iterator each time you pass it to the iter() function or use it in a for loop."

Well, "container" would be a perfectly good word if we didn't already use it to mean something different: an object with the "in" operator.

You can have collections of things that can't efficiently test containment (a lazy linked list would take linear time and space for __contains__), and containment of things that aren't even iterables (e.g., a real interval).

> I expect that no one will misunderstand you if you say the word "reiterable" in the context of checking for an exhausted iterator or an iterable that returns a new iterator each time.

The problem isn't so much whether I can use it--I do, in fact, use both "collection" and "reiterable", defining them when necessary (it often isn't necessary--but when it is, at least I only have to define them once).

It's whether other people know there's a word they can use. When they don't, they struggle to explain what they mean, and frequently make mistakes, like Paul saying that a range is not an iterable while trying to explain someone else's confusion about iterables, or whoever wrote the docs on dict views saying that they're not iterators but sequences (which took years for someone to notice and fix).


More information about the Python-ideas mailing list