def resolve_dependency(start,graph,li):
if not graph[start]:
pass
else:
for dep in graph[start]:
resolve_dependency(dep,graph,li)
if start not in 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