I know that there are modules for this type of structure, but I like and prefer to learn how everything really works. So ... I am trying to expand the path from the graph, for example, for example:

g = dict(
s=['a','d','s'],
a=['s','d','b'],
d=['s','a','e'],
b=['a','e','c'],
e=['d','b','f'],
f=['e','g'],
c=['b'],
g=['f'])
So far I see the neighbors of this node with:
def vecinosDe(n = ''):
return g[n]
I want that every time I call a function with one argument, the node graph returns a list of other nodes associated with the specified one.
Then enter the same list that was created, created for the same function, to return the nodes associated with the specified nodes in the list of the list, and sequentially until it reaches the "g" node.
I also know that I need to check if there is any recursion (loop) for the node connected to the node.
Here is the code that I still have:
def expandir(n = '', lista = []):
lista.append([n])
for v in g[n]:
for i in range(len(lista)):
lista[i].append(v)
return lista
, , , lol.
>>> expandir('s')
[['s', 'd', 'a', 's']]
>>> expandir('d')
[['S', 'D', 'A', 'S', 'S', 'A', 'E'], ['D', 'S', 'A', 'E']]
, , node, node, , node. , .
?
if n == v:
, - , ? , .: P
, ?... ?: S
- ?:)