grinpy.functions.neighborhoods.are_neighbors

grinpy.functions.neighborhoods.are_neighbors(G, v, nbunch)

Returns true if v is adjacent to any of the nodes in nbunch. Otherwise, returns false.

Parameters:
  • G (NetworkX graph) – An undirected graph.
  • v (node) – A node in the graph.
  • nbunch – A single node or iterable container
Returns:

If nbunch in a single node, True if v in a neighbor that node and False otherwise.

If nbunch is an interable, True if v is a neighbor of some node in nbunch and False otherwise.

Return type:

bool

Examples

>>> G = nx.star_graph(3) # Star on 4 nodes
>>> nx.are_neighbors(G, 0, 1)
True
>>> nx.are_neighbors(G, 1, 2)
False
>>> nx.are_neighbors(G, 1, [0, 2])
True