13. Итераторы.

class SomeIter(object):
    def __iter__(self):
        return self

    def next(self):
        raise StopIteration()

print [val for val in SomeIter()]
[]
class ContainerIter(object):
    def __init__(self, cont):
        self.cont = cont

    def next(self):
        raise StopIteration()

class Container(object):
    def __iter__(self):
        return ContainerIter(self)

print [val for val in Container()]
[]

Цикл for и итерирование