def _fast_traverse(self, cls):
 result = []
 if isinstance(self, cls):
  result.append(self)
 for child in self.children:
  result.extend(child._fast_traverse(cls))
 return result

def _fast_traverse ( self , cls ) : result = [ ] if isinstance ( self , cls ) : result . append ( self ) for child in self . children : result . extend ( child . _fast_traverse ( cls ) ) return result
version of node .