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
(self, ebunch)
| 712 | nx._clear_cache(self) |
| 713 | |
| 714 | def remove_edges_from(self, ebunch): |
| 715 | """Remove all edges specified in ebunch. |
| 716 | |
| 717 | Parameters |
| 718 | ---------- |
| 719 | ebunch: list or container of edge tuples |
| 720 | Each edge given in the list or container will be removed |
| 721 | from the graph. The edges can be: |
| 722 | |
| 723 | - 2-tuples (u, v) A single edge between u and v is removed. |
| 724 | - 3-tuples (u, v, key) The edge identified by key is removed. |
| 725 | - 4-tuples (u, v, key, data) where data is ignored. |
| 726 | |
| 727 | See Also |
| 728 | -------- |
| 729 | remove_edge : remove a single edge |
| 730 | |
| 731 | Notes |
| 732 | ----- |
| 733 | Will fail silently if an edge in ebunch is not in the graph. |
| 734 | |
| 735 | Examples |
| 736 | -------- |
| 737 | >>> G = nx.path_graph(4) # or DiGraph, MultiGraph, MultiDiGraph, etc |
| 738 | >>> ebunch = [(1, 2), (2, 3)] |
| 739 | >>> G.remove_edges_from(ebunch) |
| 740 | |
| 741 | Removing multiple copies of edges |
| 742 | |
| 743 | >>> G = nx.MultiGraph() |
| 744 | >>> keys = G.add_edges_from([(1, 2), (1, 2), (1, 2)]) |
| 745 | >>> G.remove_edges_from([(1, 2), (2, 1)]) # edges aren't directed |
| 746 | >>> list(G.edges()) |
| 747 | [(1, 2)] |
| 748 | >>> G.remove_edges_from([(1, 2), (1, 2)]) # silently ignore extra copy |
| 749 | >>> list(G.edges) # now empty graph |
| 750 | [] |
| 751 | |
| 752 | When the edge is a 2-tuple ``(u, v)`` but there are multiple edges between |
| 753 | u and v in the graph, the most recent edge (in terms of insertion |
| 754 | order) is removed. |
| 755 | |
| 756 | >>> G = nx.MultiGraph() |
| 757 | >>> for key in ("x", "y", "a"): |
| 758 | ... k = G.add_edge(0, 1, key=key) |
| 759 | >>> G.edges(keys=True) |
| 760 | MultiEdgeView([(0, 1, 'x'), (0, 1, 'y'), (0, 1, 'a')]) |
| 761 | >>> G.remove_edges_from([(0, 1)]) |
| 762 | >>> G.edges(keys=True) |
| 763 | MultiEdgeView([(0, 1, 'x'), (0, 1, 'y')]) |
| 764 | |
| 765 | """ |
| 766 | for e in ebunch: |
| 767 | try: |
| 768 | self.remove_edge(*e[:3]) |
| 769 | except NetworkXError: |
| 770 | pass |
| 771 | nx._clear_cache(self) |