Check out example codes for "representation of graph usig sets and hash in python". It will help you in understanding the concepts better.

Code Example 1

def find_path(graph, start, end, path=[]):
        path = path + [start]
        if start == end:
            return path
        if not graph.has_key(start):
            return None
        for node in graph[start]:
            if node not in path:
                newpath = find_path(graph, node, end, path)
                if newpath: return newpath
        return None

Learn ReactJs, React Native from