Category: iterators

Problem

Build iterable objects with iter.

Solution

  def __iter__(self):
    for item in self._data:
        yield item * 2
  

Notes

  • Adapt variable names and paths to your project
  • Add error handling for production use
  • See related chapters in the Learning Path