找到一个子节点的所有父节点
标签(空格分隔): python
初衷是为了找到一个子节点的所有父节点
#!/usr/bin/env python
# -*- coding:utf-8 -*-
'''
@Project: EntityLink
@Create Date: 下午5:23
@AuthOr: zkjiang
@Description:
'''
dict = {"A":"B","B":"C","C":"D","D":"E"}
list = []
def get_father( word):
if word not in dict.keys():
return []
else:
c = dict[word]
a = [dict[word]]
b = get_father(c)
return a + b
print(get_father("A"))
>>>[B,C,D,E]