end = 'g'
for v in g:
    path = next(pathiter(g, v, end), None)
if path is not None:
    print(' \xe2\x86\x92 '.join(path))
else:
    print('no path between %s and %s' % (v, end))
Расширение пути из графа