title: NetworkX / Python_igraph: All paths between two nodes, limited by list of nodes
body: <p>I am using the function from <a href="https://stackoverflow.com/a/29324009/2772305">here</a> :</p>
  
  <pre><code>def find_all_paths(graph, start, end, mode = 'OUT', maxlen = None):
  def find_all_paths_aux(adjlist, start, end, path, maxlen = None):
      path = path + [start]
      if start == end:
          return [path]
      paths = []
      if maxlen is None or len(path) &lt;= maxlen:
          for node in adjlist[start] - set(path):
              paths.extend(find_all_paths_aux(adjlist, node, end, path, maxlen))
      return paths
  adjlist = [set(graph.neighbors(node, mode = mode)) \
      for node in xrange(graph.vcount())]
  all_paths = []
  start = start if type(start) is list else [start]
  end = end if type(end) is list else [end]
  for s in start:
      for e in end:
          all_paths.extend(find_all_paths_aux(adjlist, s, e, [], maxlen))
  return all_paths
  </code></pre>
  
  <p>to find all paths between two nodes.</p>
  
  <p>An alternative function is the one <a href="https://stackoverflow.com/a/5683508/2772305">here</a>:</p>
  
  <pre><code>def find_all_paths(graph, start, end):
  path  = []
  paths = []
  queue = [(start, end, path)]
  while queue:
      start, end, path = queue.pop()
      print 'PATH', path
  
      path = path + [start]
      if start == end:
          paths.append(path)
      for node in set(graph[start]).difference(path):
          queue.append((node, end, path))
  return paths
  </code></pre>
  
  <p>I would like to extend one of the functions in order to take another argument, which would be a list of "via_nodes". </p>
  
  <p>If a path has one of those via_nodes between its end and start node, it should not be returned.</p>
  
  <p>It would be easy to first calculate all paths with the function as it is now and afterwards exclude the paths meeting above condition, but in order to make it more performant, I would like it to stop the path search once it meets a via_node at an earlier stage. </p>
  
  <p>Any ideas?</p>