On 2008-02-12, Paul Rubin <> wrote: > Paul Hankin <[EMAIL PROTECTED]> 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.
This would probably be better (in terms of memory if not beauty): def genDescendants(self): return chain([self], *(child.genDescendants() for child in self.children)) -- http://mail.python.org/mailman/listinfo/python-list