Recursive generator

Paul Rubin http
Tue Feb 12 21:32:43 CET 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