Iterables vs. Iterators vs. Generators

1 · Vincent Driessen · Sept. 25, 2014, midnight
Occasionally I've run into situations of confusion on the exact differences between the following related concepts in Python: a container an iterable an iterator a generator a generator expression a {list, set, dict} comprehension I'm writing this post as a pocket reference for later. Containers ¶ Containers are data structures holding elements, and that support membership tests. They are data structures that live in memory, and typically hold all their values in memory, too. In Python, som...