I have a huge depth dictionary that represents forest (many non-binary trees) which I want to process the forest and create a text file with all possible relations of the forest, e.g. given the dictionary:
{'a': {'b': {'c': {}, 'd': {}}, 'g': {}}}
the generated text file will look like:
a b c
a b d
a g
Note that the nested dictionary is big and iterating over it recursively is makes a memory run-time error.
What I tried doing is converting the dictionary into a list of lists recursively which yields a run-time error. The code:
def return_list(forest):
for ent in forest.keys():
lst = [new_ent] + grab_children(forest[ent])
yield lst
def grab_children(father):
local_list = []
for key, value in father.items():
local_list.append(new_key)
local_list.extend(grab_children(value))
return local_list
The error: "maximum recursion depth exceeded in comparison" RuntimeError