original_docstring: 
      This function checks whether a path exists between two nodes (node1,
      node2) in graph G.
  
      Special thanks to @ghirlekar for suggesting that we keep track of the
      "visited nodes" to prevent infinite loops from happening. This also
      removes the need to remove nodes from queue.
  
      Reference: https://github.com/ericmjl/Network-Analysis-Made-Simple/issues/3
  
      With thanks to @joshporter1 for the second bug fix. Originally there was
      an extraneous "if" statement that guaranteed that the "False" case would
      never be returned - because queue never changes in shape. Discovered at
      PyCon 2017.
  
      With thanks to @chendaniely for pointing out the extraneous "break".
  
      If you would like to see @dgerlanc's implementation, see
      https://github.com/ericmjl/Network-Analysis-Made-Simple/issues/76
      
docstring: This function checks whether a path exists between two nodes (node1,
  node2) in graph G.
  
  Special thanks to @ghirlekar for suggesting that we keep track of the
  "visited nodes" to prevent infinite loops from happening. This also
  removes the need to remove nodes from queue.
  
  
  
  With thanks to @joshporter1 for the second bug fix. Originally there was
  an extraneous "if" statement that guaranteed that the "False" case would
  never be returned - because queue never changes in shape. Discovered at
  PyCon 2017.
  
  With thanks to @chendaniely for pointing out the extraneous "break".
  
  
docstring_tokens: This function checks whether a path exists between two nodes ( node1 node2 ) in graph G . Special thanks to @ghirlekar for suggesting that we keep track of the " visited nodes " to prevent infinite loops from happening . This also removes the need to remove nodes from queue . With thanks to @joshporter1 for the second bug fix . Originally there was an extraneous " if " statement that guaranteed that the " False " case would never be returned - because queue never changes in shape . Discovered at PyCon 2017 . With thanks to @chendaniely for pointing out the extraneous " break " .
code: def path_exists_for_loop(node1, node2, G):
      """
      This function checks whether a path exists between two nodes (node1,
      node2) in graph G.
  
      Special thanks to @ghirlekar for suggesting that we keep track of the
      "visited nodes" to prevent infinite loops from happening. This also
      removes the need to remove nodes from queue.
  
      Reference: https://github.com/ericmjl/Network-Analysis-Made-Simple/issues/3
  
      With thanks to @joshporter1 for the second bug fix. Originally there was
      an extraneous "if" statement that guaranteed that the "False" case would
      never be returned - because queue never changes in shape. Discovered at
      PyCon 2017.
  
      With thanks to @chendaniely for pointing out the extraneous "break".
  
      If you would like to see @dgerlanc's implementation, see
      https://github.com/ericmjl/Network-Analysis-Made-Simple/issues/76
      """
      visited_nodes = set()
      queue = [node1]
  
      for node in queue:
          neighbors = list(G.neighbors(node))
          if node2 in neighbors:
              return True
          else:
              visited_nodes.add(node)
              queue.extend([n for n in neighbors if n not in visited_nodes])
  
      return False
code_tokens: def path_exists_for_loop ( node1 , node2 , G ) : visited_nodes = set ( ) queue = [ node1 ] for node in queue : neighbors = list ( G . neighbors ( node ) ) if node2 in neighbors : return True else : visited_nodes . add ( node ) queue . extend ( [ n for n in neighbors if n not in visited_nodes ] ) return False
short_docstring: This function checks whether a path exists between two nodes (node1,
  node2) in graph G.
short_docstring_tokens: This function checks whether a path exists between two nodes ( node1 node2 ) in graph G .
comment: """
      This function checks whether a path exists between two nodes (node1,
      node2) in graph G.
  
      Special thanks to @ghirlekar for suggesting that we keep track of the
      "visited nodes" to prevent infinite loops from happening. This also
      removes the need to remove nodes from queue.
  
      Reference: https://github.com/ericmjl/Network-Analysis-Made-Simple/issues/3
  
      With thanks to @joshporter1 for the second bug fix. Originally there was
      an extraneous "if" statement that guaranteed that the "False" case would
      never be returned - because queue never changes in shape. Discovered at
      PyCon 2017.
  
      With thanks to @chendaniely for pointing out the extraneous "break".
  
      If you would like to see @dgerlanc's implementation, see
      https://github.com/ericmjl/Network-Analysis-Made-Simple/issues/76
      """