It may be a little off-topic, but have you considered using generators?
It is as explicit, as possible. You specify that it should yield given node value, and all nodes extracted from this node:
def _recursive_extraction(node):
for subnode in node.get_subnodes():
yield subnode
yield from _recursive_extraction(subnode)
Also, there is advantage of speicfying ALGORITHM for extraction, without specifying container for extracted data.
Last, but not least, it may be a little faster/more memory efficient than first solution - if you want to iterate once over extracted nodes, then that is what you need, if you want to store it, pass this generator to list()
. If constructor is faster than extending list (and I assume it may be), you have your speedup, and you don't need intermediate data structures.