On Mar 9, 8:58 pm, duccio <[EMAIL PROTECTED]> wrote:
> Someone knows if it's possible to make this __iter__ function with just  
> one 'yield' intead of two?
> ...
>      def __iter__(self):
>          yield self #1
>          for n in self.childs:
>              for nn in n.__iter__():
>                  yield nn #2

Only one yield and shorter (but not really any simpler):

from itertools import chain

class Node:
    ...
    def __iter__(self):
        for x in chain([self], *self.childs):
            yield x

--
Paul Hankin
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to