title: Python: List all possible paths in graph represented by dictionary
body: <p>I have a dictionary with keys representing nodes and values representing possible nodes that the key can traverse to. </p>
  
  <p>Example: </p>
  
  <pre><code>dependecyDict = { 'A': ['D'], 'B': ['A', 'E'], 'C': ['B'], 'D': ['C'], 'G':['H']}
  </code></pre>
  
  <p>I want to create a new dicitonary, ChainsDict, that will contain all 'values' that each 'key' can traverse to by means of dependecyDict.</p>
  
  <p>For example, the output of the program with this example will be:</p>
  
  <pre><code>ChainsDict = {'A': ['D', 'C', 'B','E'], 'B':['A','D','C','E'], 'C':['B','A','D','E'], 'D':['C','B','A','E'], 'G': ['H']}
  </code></pre>
  
  <p>I think using a recursive algorithm is the best way to go about making a solution and I tried modifying a shortest path traversing algorithm as follows:</p>
  
  <pre><code>def helper(dependencyDict, ChainsDict):path = []
      for key in dependencyDict:
          path = path + [(recursiveRowGen(dependencyDict,key))]
      for paths in path:
          ChainsDict[paths[0]] = paths[1:]
      print(finalLineDict)
  def recursiveRowGen(dependencyDict,key,path = []):
      path = path + [key]
  
          if not key in dependencyDict:
          print("no key: ",key)
          return path
          print(dependencyDict[key])
          for blocking in dependencyDict[key]:
              if blocking not in path:
                  newpath = recursiveRowGen(dependencyDict,blocking,path)
                  if newpath:
                      return newpath             
      return path
  </code></pre>
  
  <p>This code however is having problems capturing the correct output when a key in dependecyDict has more than one value.
  I found a hacky solution but it doesn't feel very elegant. Any help is appreciated, thanks!</p>