This talk describes how the interpreter iterates over containers when any construct involving the for
keyword is used. It explains both the "old" and the "new" iteration protocols, demonstrates the difference between iterables and iterators, suggests implementation techniques to allow you to define your own iterables and iterators and points out some advantages of generators.
The talk's outline is given below. It will take approximately 25 minutes to deliver the material, the remainder being reserved for Q&A.
Iteration History (4 minutes)
Enter the Iterable (10 minutes) Recognizing Iterators Iterating over Iterators Why we Need Iterables
Writing Your Own Iterators and Iterables (10 minutes) The Basic Iterator Pattern The Advantages of Generators The Basic Iterable Pattern Python Native Iterables
Summary (1 minute)