networkx.algorithms.dag.ancestors

ancestors(G, source)[source]

Returns all nodes having a path to source in G.

Parameters
  • G (NetworkX DiGraph) – A directed acyclic graph (DAG)

  • source (node in G)

Returns

The ancestors of source in G

Return type

set()