def has_path(G, source, target):
 try:
  sp = nx.shortest_path(G, source, target)
 except nx.NetworkXNoPath:
  return False
 return True

def has_path ( G , source , target ) : try : sp = nx . shortest_path ( G , source , target ) except nx . NetworkXNoPath : return False return True
generic function taking a simple graph definition as a dictionary .