I've a Networkx graph like displayed in the following image
The image has been created using the code below
import networkx as nx
import matplotlib.pyplot as plt
G = nx.gnm_random_graph(n=20, m=30, seed=1)
nx.draw(G, with_labels=True)
plt.show()
G.add_edges_from([(2, 20), (20, 8)])
n = len(G.nodes())
retain_node_ids = [1,2]
G.add_edges_from([(u, v) for u in retain_node_ids for v in (n, n+1)])
G = nx.k_core(G, k=2)
G.remove_nodes_from([n, n+1])
nx.draw(G, with_labels=True)
plt.show()
This is a flow network and I want to remove loops like the one marked in red. This is a sample graph; in the real networks there are many loops like this and I want to detected and delete all the edges from such loops.
For instance, the flow direction is from 7 -> 8 and there is no exit, edge (7,8) is not a multiedge.
Suggestions on how to remove such loops will be really appreciated.
EDIT: Why do I want to delete the loop region inside red box? It's because the graph is directed. Let's consider the flow direction is from 7 to 8 and this is a transport network, once the consignment flows into 8 then it can be transported from 8 -> 2 or 8-> 20 but there is no exit from the loop.

