networkx.algorithms.dag.ancestors

ancestors(G, source)[source]

Returns all nodes having a path to source in G.

Parameters
GNetworkX DiGraph

A directed graph

sourcenode in G
Returns
set()

The ancestors of source in G