I'm doing a code project about resolving labyrinth, I'm using DFS algorithm to find a path from a starting point to a target point.
I've two sections of code, one with 'Yield' which I'm not authorize to use, and other but it sends a bool, I don't know how to get the path.
The first code:
def dfs_paths(self, start, target, path=None):
if path is None:
path = [start]
if start == target:
yield path
for next in self.mazegrid.adjacency[start] - set(path):
yield from self.dfs_paths(next, target, path + [next])
My question is: How to change this code from 'Yield' and 'Yield from' to return with loop?
The second code:
def explorepath (self, current, objective, visited_list, path) :
if current == objective :
return True
if current in visited_list :
return False
visited_list.append(current)
path.append(current)
for neighbor in self.mazegrid.successors(current):
if self.explorepath(neighbor, objective, visited_list, path) == True :
return True
path.remove(current)
return False
I know that the path is stocked in: path, but I don't know how to get it?