我有一个可以从所有键值输出所有可能路径的python词典.这里有一个小规模的例子来可视化我正在try 做的事情.
字典={‘父母’:[‘子元素1’,‘子元素2’],‘子元素1’:[‘子元素1_1’,‘子元素1_2’],‘子元素2’:[‘子元素2_1’,‘子元素2_2’],‘子元素3’:[],‘子元素1_1’=[‘子元素1_1’,‘子元素1_2’],‘子元素1_1_1’:[],‘子元素1_1_2’:[],‘子元素1_2’:[],‘子元素1_2’:[],‘子元素2_1’:[],‘子元素2_2’:[],‘子元素4’=[]}
我想要的输出是这样的:
家长/子元素1
家长/子元素1/child1_1
家长/子元素1/child1_1/child1_1_1
家长/子元素1/child1_1/child1_1_2
家长/子元素1/child1_2
父母/子元素2/子元素2_1
父母/子元素2/子元素2_2
家长/子元素3
家长/子元素4
.
.
.
Please note that I'd like to use it for a larger scale, so using 2 for loops I was able to output a path with parent and a 2 direct childs of it. But it doesn't work on larger scale, I think I need a for loop inside of a while true loop where I can check if a child doesn't have any childs of itself and it outputs me “Hey I'm the last one left and here is paths that are available to me" etc.
Thanks in advance and have a nice day.