I have a NetworkX graph like following.
g = nx.DiGraph()
g.add_edge('a', 'b')
g.add_edge('b', 'c')
g.add_edge('b', 'd')
g.add_edge('b', 'e')
g.add_edge('e', 'f')
I have a Python function called getHop
and it takes two parameters. One is node
and other one is hop
.
getHop(node, hop):
If node is f
and hop is 1
then getHop
should return parent node(s) of f
. In this case it is e
.
If node is f
and hop is 2
then getHop
should return grand parent node(s) of f
. In this case it is b
.
If node is f
and hop is 3
then getHop
should return great grandparent node(s) of f
. In this case it is a
.
How can I implement the above-mentioned scenario in NetworkX. Please let me know. Thanks in advance.