标签:python
‘‘‘常见数据结构-图‘‘‘
‘‘‘a指向b,a指向d,依次类推‘‘‘
charts = {‘a‘:[‘b‘,‘d‘],‘c‘:[‘e‘],‘d‘:[‘c‘,‘e‘]}
‘‘‘遍历图中的路径‘‘‘
def path(chart,x,y,pathd=[]):
pathd = pathd + [x]
if x == y:
return pathd
if not chart.has_key(x):
return None
for jd in chart[x]:
if jd not in pathd:
newjd =path(chart,jd,y,pathd)
if newjd:
return newjd
print(path(charts,‘a‘,‘e‘))本文出自 “运维杂谈Q群:223843163” 博客,请务必保留此出处http://freshair.blog.51cto.com/8272891/1896337
标签:python
原文地址:http://freshair.blog.51cto.com/8272891/1896337