Iteration in Python: Iterators, Generators, itertools, and Special Methods

PyOhio 2008
Brandon Mintern

  1. Introduction: Iteration in Python
  2. The benefits of Python's iteration model
  3. How Python interprets a for loop
  4. Special methods
  5. Defining __iter__ for an illustrative Queue class
  6. Simplifying iterator definitions with generators
  7. Improving Queue.__iter__ by using a generator
  8. itertools
  9. Combining it all, or, merged: a class for combining containers