MCPcopy Create free account
hub / github.com/easy-graph/Easy-Graph / add_edges_from

Method add_edges_from

easygraph/classes/directed_graph.py:741–804  ·  view source on GitHub ↗

Add all the edges in ebunch_to_add. Parameters ---------- ebunch_to_add : container of edges Each edge given in the container will be added to the graph. The edges must be given as 2-tuples (u, v) or 3-tuples (u, v, d) where d is a diction

(self, ebunch_to_add, **attr)

Source from the content-addressed store, hash-verified

739 print(err)
740
741 def add_edges_from(self, ebunch_to_add, **attr):
742 """Add all the edges in ebunch_to_add.
743
744 Parameters
745 ----------
746 ebunch_to_add : container of edges
747 Each edge given in the container will be added to the
748 graph. The edges must be given as 2-tuples (u, v) or
749 3-tuples (u, v, d) where d is a dictionary containing edge data.
750 attr : keyword arguments, optional
751 Edge data (or labels or objects) can be assigned using
752 keyword arguments.
753
754 See Also
755 --------
756 add_edge : add a single edge
757 add_weighted_edges_from : convenient way to add weighted edges
758
759 Notes
760 -----
761 Adding the same edge twice has no effect but any edge data
762 will be updated when each duplicate edge is added.
763
764 Edge attributes specified in an ebunch take precedence over
765 attributes specified via keyword arguments.
766
767 Examples
768 --------
769 >>> G = eg.Graph() # or DiGraph, MultiGraph, MultiDiGraph, etc
770 >>> G.add_edges_from([(0, 1), (1, 2)]) # using a list of edge tuples
771 >>> e = zip(range(0, 3), range(1, 4))
772 >>> G.add_edges_from(e) # Add the path graph 0-1-2-3
773
774 Associate data to edges
775
776 >>> G.add_edges_from([(1, 2), (2, 3)], weight=3)
777 >>> G.add_edges_from([(3, 4), (1, 4)], label="WN2898")
778 """
779 for e in ebunch_to_add:
780 ne = len(e)
781 if ne == 3:
782 u, v, dd = e
783 elif ne == 2:
784 u, v = e
785 dd = {}
786 else:
787 raise EasyGraphError(f"Edge tuple {e} must be a 2-tuple or 3-tuple.")
788 if u not in self._adj:
789 if u is None:
790 raise ValueError("None cannot be a node")
791 self._adj[u] = self.adjlist_inner_dict_factory()
792 self._pred[u] = self.adjlist_inner_dict_factory()
793 self._node[u] = self.node_attr_dict_factory()
794 if v not in self._adj:
795 if v is None:
796 raise ValueError("None cannot be a node")
797 self._adj[v] = self.adjlist_inner_dict_factory()
798 self._pred[v] = self.adjlist_inner_dict_factory()

Callers 1

parse_pajekFunction · 0.95

Calls 2

EasyGraphErrorClass · 0.90
updateMethod · 0.80

Tested by

no test coverage detected