title: Return all possible paths, having built a predecessor dictionary in Python
body: <p>If I have a predecessor dictionary for a single direction graph generated, such as:</p>
  
  <pre><code>{'A': [], 'B': ['A'], 'C': ['B'], 'D': ['B', 'C'], 'E': ['D']}
  </code></pre>
  
  <p>How could I:</p>
  
  <p>1) find all possible paths from point A to E and print them?</p>
  
  <p>Thank you!</p>
  
  <p>Code pasted below:</p>
  
  <p>Code clarification:</p>
  
  <p>G is a tuple of tuples, the inner tuples being pairs of vertices that are connected in one way: ((begin, end) (begin,end))</p>
  
  <p>s is start node</p>
  
  <p>e is end node</p>
  
  <pre><code>def dfs_stack(G,s,e):
      stack = [s] 
      vertices = set([j for t in G for j in t]) 
      visited = dict([(v, False) for v in vertices])
      predecessor = dict([(v, []) for v in vertices])
      while stack:
          u = stack.pop()
          if visited[u] == False:
              visited[u] = True
              for w in get_neighbors(u, G): 
                  if visited[w] == False:
                      predecessor[w].append(u)
                      stack.append(w)
                  elif (visited[w] == True and w != e):
                      return 'CYCLICAL GRAPH'
      return predecessor_to_path(predecessor,s, e)
  
  def predecessor_to_path(pdict, s, end, l=[]):
      l.append(end)
      if end == s:
          return l
      else:
          for p in pdict[end]:
             return predecessor_to_path(pdict, s, p, l)
  </code></pre>
  
  <p>Currently, this only returns the shortest path. Any ideas on how predecessor_to_path could be modified to return ALL paths?</p>