找到一个子节点的所有父节点

找到一个子节点的所有父节点

标签(空格分隔): 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]
阅读更多

没有更多推荐了,返回首页