Recursive generator

Paul Rubin http
Tue Feb 12 15:32:43 EST 2008


Paul Hankin <paul.hankin at gmail.com> writes:
> def genDescendants(self):
>     return chain([self], *[child.genDescendants()
>         for child in self.children])

That is scary.  It generates an in-memory list the size of the
whole subtree, at every level.  Total memory consumption is maybe
even quadratic, depending on the tree shape, but even if it's
only linear, it's way ugly.



More information about the Python-list mailing list