def bidirectional_shortest_path(G, source, target):
 if ((source not in G) or (target not in G)):
  msg = 'Either source {} or target {} is not in G'
  raise nx.NodeNotFound(msg.format(source, target))
 results = _bidirectional_pred_succ(G, source, target)
 (pred, succ, w) = results
 path = []
 while (w is not None):
  path.append(w)
  w = pred[w]
 path.reverse()
 w = succ[path[(-1)]]
 while (w is not None):
  path.append(w)
  w = succ[w]
 return path

def bidirectional_shortest_path ( G , source , target ) : if ( ( source not in G ) or ( target not in G ) ) : msg = 'Either source {} or target {} is not in G' raise nx . NodeNotFound ( msg . format ( source , target ) ) results = _bidirectional_pred_succ ( G , source , target ) ( pred , succ , w ) = results path = [ ] while ( w is not None ) : path . append ( w ) w = pred [ w ] path . reverse ( ) w = succ [ path [ ( - 1 ) ] ] while ( w is not None ) : path . append ( w ) w = succ [ w ] return path
return a list of nodes in a shortest path between source and target .