def resolve_dependency(start,graph,li): ifnot graph[start]: pass else: for dep in graph[start]: resolve_dependency(dep,graph,li) if start notin li: li.append(start)
if__name__=='__main__': graph ={'A':['D'],'B':['C'],'C':[],'D':['C']} start ='D' li =[] resolve_dependency(start,graph,li) li.pop() print li