;<'+str(self.data)+'>'
> def __iter__(self):
> yield self #1
> for n in self.childs:
> for nn in n.__iter__():
> yield nn #2
>
> n=Node()
> n.appendNode(1).appendNode(2).appendNode(3).appendNode(4)
> n.
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:
>>>>
__ function with just
> > > one 'yield' intead of two?
> > > ...
> > > def __iter__(self):
> > > yield self #1
> > > for n in self.childs:
> > > for nn in n.__iter__():
> > >
> 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
>
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.chil
def __iter__(self):
> yield self #1
> for n in self.childs:
> for nn in n.__iter__():
> yield nn #2
Nope. There have been numerous discussions about this, introducing
something like a yield_all-keyword or such thing that would replace the
a=data
def appendNode(self, n):
node=Node(n)
self.childs.append(node)
return node
def __str__(self):
return '<'+str(self.data)+'>'
def __iter__(self):
yield self #1
for n in self.childs:
for nn i