In this function I'm trying to recursively find all paths from the children of a node to the goal which are shorter than the maxDistance, and build up a complete list of routes.

def validPaths(graph, start, end, maxTotalDist, path = []): """ start and end are nodes in the graph maxTotalDistance is an int which should be the limit of how far you should travel on a weighted graph""" path = path + [start] if start == end: return path allChildrenPaths = [] if getTotalLength(path, graph) < maxTotalDist: # check to make sure the path is shorter than MaxTotalDistance for child in graph.childrenOf(start): if child not in path: # so it doesn't contain loops, only include new nodes. newPaths = validPaths(graph, child, end, maxTotalDist, path) #find all valid paths for the child if newPaths != None: allChildrenPaths = allChildrenPaths + newPaths #generates a list of all the paths from all the children validPathsList = [] for route in allChildrenPaths: #take all the children's paths, and append the parent node validPathsList.append([start] + route) return validPathsList

Here is what I have so far, but it doesn't work properly. It seems to give me a short route, and then a bunch of empty lists until it gets to an error when trying to append a node to a list, though, I don't understand where this is coming from. Please help me find the error in my code. At first I would appreciate hints and general nudges in the right direction so I can understand what I'm doing wrong and learn from it.