ancestors¶
- ancestors(G, source)[source]¶
Returns all nodes having a path to
sourceinG.- Parameters
- GNetworkX Graph
- sourcenode in
G
- Returns
- set()
The ancestors of
sourceinG
- Raises
- NetworkXError
If node
sourceis not inG.
See also
Examples
>>> DG = nx.path_graph(5, create_using=nx.DiGraph) >>> sorted(list(nx.ancestors(DG, 2))) [0, 1]