class t:

    def __init__(self):
        self.l = []
self.a = 0

def __iter__(self):
    for child in self.l:
        for item in child:
            yield item
yield self
python iterator through tree with list of children