class Map():
def returnWay(self, node1, node2):
final_list = []
temp_list = []
self._returnWay(node1, node2, final_list, temp_list)
return final_list
def _returnWay(self, node1, node2, final_list, temp_list):
if node1 not in temp_list:
temp_list.append(node1)
if node1 == node2:
final_list.append(temp_list)
del temp_list[-1]
else:
for x in node1.nexts():
self._returnWay(x, node2, final_list, temp_list)
del temp_list[-1]
path = Map()
for x in path.returnWay(node1, node2):
print x
Ok guys, first than anything I don't speak english really, so excuse me if I make some mistakes speaking...
Here I'm trying to get all the existing ways between two nodes, there are 4 of them, but instead I'm getting 4 empty lists.
If I put in line 13 "for x in temp_list: print x" It prints all the 4 ways, but for some reason It doesn't add them to final_list.
node1 == node2) you calldel temp_list[-1]twice, once before returning and once after returning. I'm not so sure how your code is supposed to work, but this is the first think that strikes me.node.nexts()returns all the successor nodes ofnode? Is the graph directed?final_list.append(temp_list[:]).