Skip to main content
`Ctrl`+`K`

# MultiDiGraph.remove_edges_from

MultiDiGraph.remove_edges_from(ebunch)

  Remove all edges specified in ebunch.

  Parameters:
    ebunch: list or container of edge tuples

      Each edge given in the list or container will be removed from the graph. The edges can be:

      > - 2-tuples (u, v) A single edge between u and v is removed.

      > - 3-tuples (u, v, key) The edge identified by key is removed.

      > - 4-tuples (u, v, key, data) where data is ignored.

  See also

  `remove_edge`

    remove a single edge

  Notes

  Will fail silently if an edge in ebunch is not in the graph.

  Examples

      >>> G = nx.path_graph(4)  # or DiGraph, MultiGraph, MultiDiGraph, etc
      >>> ebunch = [(1, 2), (2, 3)]
      >>> G.remove_edges_from(ebunch)

  Removing multiple copies of edges

      >>> G = nx.MultiGraph()
      >>> keys = G.add_edges_from([(1, 2), (1, 2), (1, 2)])
      >>> G.remove_edges_from([(1, 2), (2, 1)])  # edges aren't directed
      >>> list(G.edges())
      [(1, 2)]
      >>> G.remove_edges_from([(1, 2), (1, 2)])  # silently ignore extra copy
      >>> list(G.edges)  # now empty graph
      []

  When the edge is a 2-tuple `(u, v)` but there are multiple edges between u and v in the graph, the most recent edge (in terms of insertion order) is removed.

      >>> G = nx.MultiGraph()
      >>> for key in ("x", "y", "a"):
      ...     k = G.add_edge(0, 1, key=key)
      >>> G.edges(keys=True)
      MultiEdgeView([(0, 1, 'x'), (0, 1, 'y'), (0, 1, 'a')])
      >>> G.remove_edges_from([(0, 1)])
      >>> G.edges(keys=True)
      MultiEdgeView([(0, 1, 'x'), (0, 1, 'y')])