Python - Recursively Create Arbitrarily Nested Dict Given Three Different Lists
Suppose I am given three lists: a list of roots, a list of children (which can have children), and a list of nodes. On any of the items in these lists, I can call use an attribute
Solution 1:
def _build_structure(self, item)
if item in list_of_nodes:
return item
else:
return [self._build_structure(child) for child in item.children]
you need to return your recursive call ... if you need more help you will need to post a minimal example of list_of_nodes
....
Post a Comment for "Python - Recursively Create Arbitrarily Nested Dict Given Three Different Lists"