Generate all leaf-to-root paths in a dictionary tree in Python
问题 I have a dictionary-tree in an "non-standard" form like so: tree = {'0': {'A': {'B': {'C': {}}}}, {'D': {'E': {}}, {'F': {}}}} Leaf nodes are defined as dictionary key-value pairs where the values is an empty dictionary. I would like to extract all the leaf-to-root paths as lists of lists like so: paths_ = [['C', 'B', 'A', '0'], ['E', 'D', '0'], ['F', 'D', '0']] The paths can be reversed too if that is helpful. paths_ = [['0', 'A', 'B', 'C'], ['0', 'D', 'E'], ['0', 'D', 'F']] I know I have to